From 23a7f9de4e3ec8716b58f6eccc63bd207f4a2e35 Mon Sep 17 00:00:00 2001 From: James Wigger Date: Tue, 10 Sep 2019 10:01:34 +0100 Subject: [PATCH] Adds readme, changes method signatures --- .gitignore | 1 + README.md | 81 +++++++++++++++++++++++++++++++++++++++ composer.json | 25 ++++++++++++ redfinch-image-resize.php | 2 +- 4 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 README.md create mode 100644 composer.json diff --git a/.gitignore b/.gitignore index 090a1f0..d66edda 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea .DS_Store +vendor diff --git a/README.md b/README.md new file mode 100644 index 0000000..2e121a2 --- /dev/null +++ b/README.md @@ -0,0 +1,81 @@ +# WordPress Image Resize + +WordPress can be difficult to work with when using images. Especially if you want to have multiple image sizes +available for templates, the result is either putting the resizing responsibility on end users or having an extremely +large uploads directory. + +This plugin aims to solve this issue, simply and without any additional libraries. It will automatically add your custom +sizes to the Attachment meta data which means on deletion, all of the arbitrary sizes will be removed as well. + +## Installation + +If you are using `roots/bedrock` or a variant of this, the installation is simply to +run `composer require redfinch/redfinch-image-resize`. + +To install manually go to the releases page and download the latest version. Unzip the file into your WordPress plugins +directory. + +## Using the plugin + +The plugin is aimed at developers and therefore there is no admin interface. The plugin exposes four main functions: + +### redfinch\_resize\_image + +This resizes an image proportionally to fit X and Y values. + +```php + +``` + +### redfinch\_resize\_post\_thumbnail + +This is a helper function to resize the featured image of the current post. You can optionally pass through +a `WP_Post` or post ID value as the last parameter to display the image from a specific post or page. + +```php + +``` + +### redfinch\_crop\_image + +This is very similar to the `resize()` function, however it will crop the image to fit ensuring that +the image is always going to be the given dimensions. + +```php + +``` + +### redfinch\_crop\_post\_thumbnail + +Identical to `resize()`, instead ensuring the featured image is always the given dimensions. You can optionally pass through +a `WP_Post` or post ID value as the last parameter to display the image from a specific post or page. + +```php + +``` + +## Hooks + +### Filters + +#### redfinch\_image\_resize\_get\_path + +Returns the generated path to the resized image. The value passed through is a string and +it expects a string to be returned. + +#### redfinch\_image\_resize\_get\_url + +Returns the generated URL to the resized image. The value passed through is a string and +it expects a string to be returned. + +### Actions + +#### redfinch\_image\_resize\_pre\_generate\_image + +This action triggers before the `resize()` method is called on the `WP_Image_Editor` object. The single parameter +is the Image Editor instance. + +#### redfinch\_image\_resize\_post\_generate\_image + +This action triggers after the `resize()` method is called on the `WP_Image_Editor` object. The single parameter +is the Image Editor instance. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a5062fc --- /dev/null +++ b/composer.json @@ -0,0 +1,25 @@ +{ + "name": "redfinch/redfinch-image-resize", + "description": "Provides simple helper functions for resizing images uploaded to WordPress", + "homepage": "https://github.com/RedFinch/WordPress-Image-Resize", + "type": "wordpress-plugin", + "license": "MIT", + "authors": [ + { + "name": "James Wigger", + "email": "james@redfinch.dev", + "homepage": "https://redfinch.dev/" + } + ], + "support": { + "issues": "https://github.com/RedFinch/WordPress-Image-Resize/issues", + "source": "https://github.com/RedFinch/WordPress-Image-Resize" + }, + "config": { + "sort-packages": true, + "preferred-install": "dist" + }, + "require": { + "php": ">=7.1" + } +} diff --git a/redfinch-image-resize.php b/redfinch-image-resize.php index 7f47734..bded12c 100644 --- a/redfinch-image-resize.php +++ b/redfinch-image-resize.php @@ -23,7 +23,7 @@ * @return string * @throws \Exception */ -function redfinchresize_image(int $attachment_id, int $width, int $height): ?string +function redfinch_resize_image(int $attachment_id, int $width, int $height): ?string { try {