{"id":15656906,"url":"https://github.com/getdave/wp-intervention","last_synced_at":"2025-05-05T15:27:12.134Z","repository":{"id":9594214,"uuid":"62703473","full_name":"getdave/wp-intervention","owner":"getdave","description":"On-demand image manipulation for WordPress via the Intervention Library.","archived":false,"fork":false,"pushed_at":"2023-01-05T16:27:23.000Z","size":888,"stargazers_count":26,"open_issues_count":14,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-30T00:06:51.613Z","etag":null,"topics":["image-manipulation","imagick","intervention","intervention-image","intervention-library","wordpress","wordpress-plugin","wp-intervention"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/getdave.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-06T08:12:47.000Z","updated_at":"2024-05-24T19:13:03.000Z","dependencies_parsed_at":"2023-01-11T20:12:50.681Z","dependency_job_id":null,"html_url":"https://github.com/getdave/wp-intervention","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getdave%2Fwp-intervention","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getdave%2Fwp-intervention/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getdave%2Fwp-intervention/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getdave%2Fwp-intervention/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/getdave","download_url":"https://codeload.github.com/getdave/wp-intervention/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252523333,"owners_count":21761902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["image-manipulation","imagick","intervention","intervention-image","intervention-library","wordpress","wordpress-plugin","wp-intervention"],"created_at":"2024-10-03T13:04:45.092Z","updated_at":"2025-05-05T15:27:12.076Z","avatar_url":"https://github.com/getdave.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WP Intervention\n\nWP Intervention provides on-demand image manipulation for WordPress via the [Intervention Library](http://image.intervention.io/).\n\n## Why?\n\nTraditionally, WordPress only provides fairly basic image manipulation facilities (eg: resize, crop). But what if you need to do more with your images? This is where WP Intervention comes in.\n\nWith WP Intervention you have the full suite of PHP Intervention's [powerful image manipulation tools](http://image.intervention.io/) at your finger tips including:\n\n* [Blur](http://image.intervention.io/api/blur).\n* [Grayscale](http://image.intervention.io/api/greyscale).\n* [Mask](http://image.intervention.io/api/mask).\n\n...and many more!\n\nResulting images are cached to avoid any further unnecessary processing.\n\n## How?\n\nAll image manipulation is provided by the [PHP Intervention Library](http://image.intervention.io/).\n\nWP Intervention merely provides a wrapper around Intervention and a convenient global function for use with WordPress.\n\nThis Plugin is currently aimed at __developers__ and aims to be fully customisable via liberal usage of [WordPress filters](https://developer.wordpress.org/reference/functions/apply_filters/).\n\n\n## Installation\n\n1. [Download a copy of this\nrepository](https://github.com/getdave/wp-intervention/archive/master.zip).\n\n2. Unzip and place the resulting folder within your  WordPress Plugins directory (typically `wp-content/plugins`).\n\n3. Activate the Plugin from within WP Admin.\n\nPlease note: you will not see any settings pages within WP Admin. This Plugin currently\nrequires you to call the image helper functions manually (see [Usage](#usage) below).]\n\n### Requirements\n\n- PHP \u003e=5.4\n- Fileinfo Extension\n\n### Supported Image Libraries\n\n- GD Library (\u003e=2.0)\n- Imagick PHP extension (\u003e=6.5.7)\n\nPlease refer to the [Intervention Library](http://image.intervention.io/) for\nfull details.\n\n## Usage\n\n### Getting Started\n\n- [Install the Plugin](#installation) and Activate.\n- Use the Plugin in your Theme or Plugin.\n\n### Basic Usage\n\nWP Intervention exposes a global helper `wp_intervention` for use in your Theme.\n\nThe API for this is:\n\n```php\nwp_intervention( string $src, array $intervention_args [, array $options] );\n```\n\nThe first parameter (`$src`) is the source image to be processed. This can be either:\n\n* a file path to an image (eg:\n`~/public_html/web/wp-content/uploads/foo.jpg`).\n* a publicly\naccessible URL (eg: `https://example.com/wp-content/uploads/foo.jpg`).\n\n### Intervention Arguments\n\nThe second `$intervention_args` parameter is an settings array which determines the transformations to be applied to the image.\n\nWP Intervention supports the [same API as the underlying Intervention Library](http://image.intervention.io/). Indeed, under the hood the Plugin simply *proxies all arguments as method calls to PHP Intervention*.\n\nIn the associative settings array the key should be the Intervention transformation name (eg: `fit`, `blur`...etc) and the value should be the arguments to pass to that transformation.\n\n#### Example Usage\n\n```php\n// Define a source image\n$original_img = \"...\"; // source image file path or URL here\n\n// An array of args to be *invoked* on Intervention\n$intervention_args = array(\n\n\t// http://image.intervention.io/api/fit\n\t'fit' =\u003e array(\n\t\t'100',\n\t\t'600'\n\t),\n\n\t// http://image.intervention.io/api/blur\n\t'blur' =\u003e 20,\n\n\t// http://image.intervention.io/api/rotate\n\t'rotate' =\u003e -45\n);\n\n// Call the global helper function\n$img_src = wp_intervention( $original_image, $intervention_args );\n```\n\nMethods are invoked on the underlying Intervention library in the *order defined in the arguments array*.\n\nRefer to the [documentation](http://image.intervention.io/) to learn more about the capabilities of Intervention (hint: it's pretty fully featured!).\n\n### Options\n\nNote: these are not the image manipulation arguments passed to the Intervention Library.\n\nThere are also various options which can be modified by passing a 3rd argument to the global function on a per use case basis.\n\n```php\nwp_intervention( $original_image, $intervention_args, array(\n\t'quality' =\u003e 100,\n\t'cache'   =\u003e false, // be careful about modifying this (see below)\n\t'debug'   =\u003e true, // enable verbose debug mode\n) );\n```\n\n#### Options Settings\n\n##### quality\n\nType: Integer\n\nDefault: 80\n\nDescription: A image quality setting ranging from 0-100.\n\n##### cache\n\nType: Boolean\n\nDefault: true\n\nDescription: Whether or not to cache this particular image. If false the image will be re-generated by Intervention on each request which may place undue load on your server. Use wisely...\n\n##### debug\n\nType: Boolean\n\nDefault: value of `WP_DEBUG` constant or (if not defined) `false`.\n\nDescription: Enable verbose debugging mode. Will throw and enable exceptions which would otherwise be silently caught by the wrapper. Useful for debugging.\n\n#### Overriding the Default Options\n\nThe default settings for the options (see above) can be overidden globally by filtering on the hook `wpi_default_options`. For example\n\n```php\nfunction modify_default_options( $options ) {\n\t$options['cache'] = false;\n    return $options;\n}\nadd_filter( 'wpi_default_options', 'modify_default_options' );\n```\n\n## Image Driver Configuration\n\nIntervention allows you to configure either GD or Imagick as the primary image driver. By default this is GD but you can overide this by filtering on the `wpi_driver` hook.\n\n```php\nfunction modify_wpi_driver( $driver ) {\n\t$driver = 'imagick';\n    return $driver;\n}\nadd_filter( 'wpi_driver', 'modify_wpi_driver' );\n```\n\nNote if you pass an unsupported driver then this is your problem...\n\n## Caching\n\nWP Intervention will cache generated images on disk to avoid repeatedly processing images. By default the cache resides at:\n\n`/wp-content/uploads/intervention/cache/`\n\nNote: the exact path may vary depending on the settings of your individual WordPress installation.\n\n### Altering the default cache location\n\nIf for any reason you need to change the default location of the cache you can filter on the `wpi_cache_directory` hook.\n\n```php\nfunction modify_wpi_cache_dir( $dir ) {\n\t$dir = '/some/random/location/you/need/to/set/';\n    return $dir;\n}\nadd_filter( 'wpi_cache_directory', 'modify_wpi_cache_dir' );\n```\n\nYou are responsible for ensuring this path is writable by PHP and publicly accessible.\n\n### Cache Garbage Collection\n\nWP Intervention automatically removes cached images that have not been accessed for 24hrs.\n\nTo do this each time a cached image is accessed by WP Intervention it's timestamp is updated via PHP's `touch()` method. A WP Cron job then runs every hour checking for any \"stale\" images that are older than 24hrs. Any matching images are deleted.\n\nIf for any reason you need to alter the duration cached files are allowed to reside on disk before they become stale, then you can filter on the `wpi_clean_outdate_cache_files_period` hook.\n\n```php\nfunction modify_wpi_cache_files_period( $period ) {\n\t$period = 604800; // 1 week\n    return $period;\n}\nadd_filter( 'wpi_clean_outdate_cache_files_period', 'modify_wpi_cache_files_period' );\n```\n\nSimilarly if you need to alter how often the cron job reoccurs then you can filter on `wpi_clean_outdate_cache_files_cron_recurrance`.\n\n```php\nfunction modify_wpi_clean_outdate_cache_files_cron_recurrance( $recurrance ) {\n\t$recurrance = 'twicedaily';\n    return $recurrance;\n}\nadd_filter( 'wpi_clean_outdate_cache_files_cron_recurrance', 'modify_wpi_clean_outdate_cache_files_cron_recurrance' );\n```\n\n## Contributing\n\nContributions to the WP Intervention Plugin are welcome. Please make a pull request!\n\n## License\n\nWP Intervention Plugin is licensed under the [MIT License](http://opensource.org/licenses/MIT).\n\nIntervention Image is licensed under the [MIT License](http://opensource.org/licenses/MIT).\nCopyright 2014 [Oliver Vogel](http://olivervogel.net/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetdave%2Fwp-intervention","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgetdave%2Fwp-intervention","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgetdave%2Fwp-intervention/lists"}