junaidbhura / fly-dynamic-image-resizer

Fly Dynamic Image Resizer plugin for WordPress
https://wordpress.org/plugins/fly-dynamic-image-resizer/
MIT License
162 stars 26 forks source link

Crop by coordinates (enhancement) #48

Closed mupic closed 3 years ago

mupic commented 3 years ago

Hello dear friend, this is a good plugin, thank you so much for developing and supporting it. I would like to make a proposal for adding a function for cropping images by exact coordinates (or even percentages to make it even easier).

Here is an example of a situation: I need to optimize the size of a large image in the header for mobile devices, in gutenberg there is an option to select the centering position of the image (background-position), and in order for this to work well on mobile phones with a cropped picture, I need to crop the image so that it corresponded to centering as in the big picture.

Usage example:

$position = array('right', 'bottom'); //Normal use
$position = array(100, 300); // Coordinates are relative to the original size
$position = array(0.7, 0.3); // Floating point numbers are calculated as percentages, relative to their original size.
echo fly_get_attachment_image(get_post_thumbnail_id(), array(480, 640), $position);

The wp_get_image_editor class has the crop method necessary for this, as I understand it will need to be called before the resize method.

junaidbhura commented 3 years ago

Thanks @mupic ! Glad you find this plugin useful.

Let me take a deeper look at this and get back to you!

mupic commented 3 years ago

I have an alternative suggestion on this topic: since this is a plugin for developers, it would be better to add the ability to work with the WP_Image_Editor class, and your plugin will give the developer the ability to save images to the cache.

If a developer needs something more than standard functionality, then he can write it himself.

junaidbhura commented 3 years ago

Hi @mupic thanks for taking the time out to create this issue. After thinking about this, I think that this feature might not be a good fit for this plugin, since the goal is to keep this plugin really light-weight and simple. As such, I'm going to close this issue, but please feel free to continue this discussion here.

mupic commented 3 years ago

Regarding my previous comment, @junaidbhura, what do you think about giving developers more flexibility with images if they need it? It will not take much effort from you, except to give a couple of methods to get the picture and save it.

junaidbhura commented 3 years ago

Hey @mupic I think I'd like to keep the functionality of this plugin minimal. There are some upcoming changes to this plugin that would get more priority: https://github.com/junaidbhura/fly-dynamic-image-resizer/issues/26