このシンプルで詳細なチュートリアルでは、PowerPoint をインストールせずに Python を使用して PPTX に画像の透かしを追加する方法に焦点を当てます。このアプリケーションを使用して、macOS、Windows、または Linux 内の .NET Core および Python で構成された環境のいずれかで、Python を使用して PowerPoint 透かしの背景画像を追加することができます。
Python で PPTX プレゼンテーションに画像透かしを追加する手順
- プレゼンテーション内に画像の透かしを挿入するための .NET 経由の Python 用 Aspose.Slides をインストールする環境を確立します
- 既存のプレゼンテーションにアクセスするか、新しいプレゼンテーションを作成して、Presentation クラス オブジェクトを使用して透かし画像を追加します
- プレゼンテーション画像コレクション内に目的の透かし画像を挿入します
- プレゼンテーション Master Slide/s コレクション内の各図形をトラバースします
- マスタースライドコレクション内のすべてのスライドに、目的の画像を含む額縁形状を挿入します
- 図形にロックを適用して、画像の透かしを固定します
- 画像の透かしを含むプレゼンテーションをディスクに保存します
上記の *Python の手順では、非常に単純な API インターフェイスと数行のコードを使用して、PPT に画像の透かしを追加します。このプロセスは、既存のプレゼンテーションをロードするか、ディスクから目的の透かし画像をロードして新しいプレゼンテーションを作成することによって開始されます。次に、プレゼンテーション マスター スライド コレクション内の各スライドが繰り返され、透かし画像を使用した画像フレームが作成されます。最後に、アクセスや編集から保護するために、各形状に異なるロックが適用されます。
Python を使用して PPTX に画像透かしを追加するコード
import aspose.pydrawing as drawing | |
import aspose.slides as slides | |
filespath = "C://Slides//" | |
#Insert the licence for Aspose.Slides | |
slidesWatermarkLicense = slides.License() | |
slidesWatermarkLicense.set_license(filespath + "Conholdate.Total.Product.Family.lic") | |
# Generate an empty presentation using the Presentation class object | |
with slides.Presentation() as watermarkPptxPresentation: | |
with open(filespath + "sample.png", "rb") as binary_file: | |
#Read the whole file at once | |
imageFileData = binary_file.read() | |
#Insert the image insdie the images collection of the presentation | |
imageForSlide = watermarkPptxPresentation.images.add_image(imageFileData) | |
#Access the master slides collection for adding a watermark image | |
for masterSlide in watermarkPptxPresentation.masters: | |
#Adding a Ppt watermark shape for logo image | |
pptxWatermarkFrame = slideForPng.shapes.add_picture_frame(slides.ShapeType.RECTANGLE, 200, 200, 200, 50, imageForSlide) | |
#Set the rotation angle of the shape | |
pptxWatermarkFrame.rotation = 325 | |
#Lock Pptx watermark image shape for protection in PowerPoint | |
pptxWatermarkFrame.shape_lock.size_locked = True | |
pptxWatermarkFrame.shape_lock.select_locked = True | |
pptxWatermarkFrame.shape_lock.position_locked = True | |
# Save the presentations with the watermark on the disk | |
watermarkPptxPresentation.save(filespath + "PresentationWithWatermarkmage.pptx", slides.export.SaveFormat.PPTX) | |
print("Done") |
PPT で透かし画像を追加するために Python* ベースの API が上記の例で効果的に使用されています。 shape_lock クラスが使用され、ロック選択、サイズ変更、位置の変更を含むさまざまな形状ロックを提供し、PowerPoint でも形状へのアクセスを防止します。
このトピックでは、Python を使用して PPTX に透かし画像を配置し、プレゼンテーション内に知的財産権を埋め込む方法を学びました。プレゼンテーション内にテキスト ベースの透かしを追加することに関心がある場合は、Pythonを使用してPPTXにドラフト透かしを挿入する方法 の記事を参照してください。