Image Optimize
A framework for image optimization that provides pipelines with processors to optimize images, with built-in integration for Drupal core image styles.
imageapi_optimize
インストール
composer require 'drupal/imageapi_optimize:^4.1'
概要
Image Optimizeモジュールは、Drupalにおける画像最適化のための包括的なフレームワークを提供します。このモジュールは「パイプライン」システムを導入しており、各パイプラインには画像を最適化するために順番に適用される複数の「プロセッサ」が含まれています。
画像を最適化するには、パイプラインに画像を渡します。パイプラインは、設定されたウェイト順に各プロセッサを画像に適用するよう調整します。例えば、画像から不要なメタデータを削除するロスレス最適化用のパイプラインと、サードパーティのWebサービスを通じて再圧縮を適用するロッシーパイプラインを用意できます。
このモジュールはDrupalの画像スタイルに対する組み込みサポートを提供します。通常の画像スタイルエフェクトが適用された後、派生画像は設定可能な最適化パイプラインを通じて自動的に処理されます。サイト全体のデフォルトパイプラインを設定することも、各画像スタイルに個別に特定のパイプラインを設定することもできます。
このモジュール自体にはプロセッサプラグインは含まれていません。Image Optimize Binaries、Image Optimize reSmush.it、Image Optimize TinyPNG、Krakenなど、実際の画像最適化プロセッサを提供する追加モジュールをインストールする必要があります。
Features
- 複数のプロセッサを持つ画像最適化パイプラインの作成と管理
- パイプライン内のプロセッサのドラッグ&ドロップによる並べ替え
- ウェイトベースのプロセッサ実行順序
- すべての画像スタイルに対するサイト全体のデフォルトパイプラインの設定
- 個々の画像スタイルへの特定パイプラインの割り当て
- Drupal Coreの画像スタイルとの自動統合 - エフェクト適用後に派生画像が最適化される
- パイプライン変更時のキャッシュ画像のフラッシュ
- パイプライン削除時の代替パイプライン選択
- カスタム画像プロセッサ作成のための拡張可能なプラグインシステム
- 設定可能なプロセッサプラグインと設定不要なプロセッサプラグインの両方をサポート
- 最適化処理中の一時ファイル管理
- キャッシュ無効化との統合
- 設定エンティティのエクスポート/インポートサポート
Use Cases
Lossless image optimization
Create a pipeline with processors that remove unnecessary metadata from images without reducing quality. This is ideal for production sites where you want smaller file sizes but cannot accept any quality loss. Use processors like jpegtran (for JPEG) and optipng (for PNG) from the Image Optimize Binaries module.
Lossy image compression
Create a pipeline with processors that apply lossy compression for maximum file size reduction. Use a service like TinyPNG or reSmush.it that intelligently compresses images. This is ideal for sites with many images where bandwidth is a concern and some quality loss is acceptable.
Multi-stage optimization pipeline
Create a pipeline with multiple processors in sequence. For example, first use jpegtran to strip metadata, then use jpegoptim to apply lossy compression. The weight system ensures processors run in the correct order.
Different optimization per image style
Assign different pipelines to different image styles. Use aggressive lossy compression for thumbnail styles where quality is less important, and lossless optimization for full-size images where quality matters.
Sitewide default with exceptions
Set a sitewide default pipeline for general optimization, then override it for specific image styles that need different treatment. For example, use lossless optimization as the default but use aggressive compression for gallery thumbnails.
Tips
- Start with a simple lossless optimization pipeline and measure the file size savings before adding lossy compression.
- Use the 'Flush' operation sparingly on production sites as it forces regeneration of all image derivatives.
- The sitewide default pipeline feature allows you to change your optimization strategy globally without editing each image style.
- Processors are executed in weight order - use this to chain multiple optimization steps effectively.
- Test your optimization pipelines with representative images before deploying to ensure acceptable quality and file size.
- For development, you can use '- None -' as the pipeline to skip optimization and speed up testing.
Technical Details
Admin Pages 7
/admin/config/media/imageapi-optimize-pipelines
Main administration page for managing image optimization pipelines. Lists all existing pipelines with their names and provides operations to edit, delete, or flush each pipeline. The page also includes a form to set the sitewide default pipeline that will be used when 'Sitewide default pipeline' is selected in image style configuration.
/admin/config/media/imageapi-optimize-pipelines/add
Form to create a new image optimization pipeline. After creation, you will be redirected to the edit form to add processors.
/admin/config/media/imageapi-optimize-pipelines/manage/{pipeline}
Form to configure an existing pipeline by adding, editing, removing, and reordering processors. Shows a table of all processors in the pipeline with drag-and-drop reordering capability.
/admin/config/media/imageapi-optimize-pipelines/manage/{pipeline}/delete
Confirmation form for deleting a pipeline. If other pipelines exist, you can optionally select a replacement pipeline to update dependent configurations.
/admin/config/media/imageapi-optimize-pipelines/manage/{pipeline}/flush
Confirmation form to flush all cached derivative images that use this pipeline. This forces regeneration of all image derivatives with the current pipeline configuration.
/admin/config/media/image-styles
The core Image styles listing page is enhanced to show an 'Image Optimize Pipeline' column for each style, displaying which pipeline (if any) is assigned to each style.
/admin/config/media/image-styles/manage/{style}
The core image style edit form is enhanced with an Image Optimize Pipeline dropdown that allows you to select which optimization pipeline to apply after all image effects have been processed.
権限 1
Hooks 2
hook_imageapi_optimize_processor_info_alter
Allows modules to alter the image optimize processor plugin definitions discovered by the plugin manager.
hook_imageapi_optimize_pipeline_flush
Invoked when a pipeline is flushed, allowing other modules to perform additional cache clearing or cleanup operations.
Troubleshooting 5
Ensure you have at least one processor module installed (e.g., imageapi_optimize_binaries). Verify a pipeline has been created with at least one processor, and that the pipeline is assigned to the image style (either as default or explicitly).
Install a processor module such as imageapi_optimize_binaries, imageapi_optimize_resmushit, or imageapi_optimize_tinypng. The base module does not include any processors.
After modifying a pipeline, you may need to flush the pipeline and regenerate image derivatives. Use the 'Flush' operation on the pipelines list page, or flush the associated image styles.
If you see errors about missing processors, the processor module may need to be re-enabled. The module includes an update hook (8003) that attempts to re-enable processor modules automatically.
Ensure the imageapi_optimize module is properly enabled. The module alters the image style form and entity to add the pipeline field.
Security Notes 3
- The 'Administer Image Optimize pipelines' permission should only be granted to trusted administrators as misconfigured processors could potentially affect site performance.
- When using external services (TinyPNG, reSmush.it, Kraken), images are sent to third-party servers for processing. Consider this when handling sensitive images.
- API keys for external services should be stored securely in configuration and not exposed in version control.