Make WordPress Core

Opened 6 years ago

Last modified 6 years ago

#46777 new enhancement

Pass attachment ID to image_resize_dimensions to allow reliable per image cropping

Reported by: arkimedia's profile arkimedia Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch
Focuses: administration Cc:

Description

This patch passes optional attachment ID parameter to image_resize_dimensions filter. The purpose of this patch is to allow plugin developers to hook into image_resize_dimensions filter and implement reliable per image cropping.

Currently many plugins rely on ugly "capture ID" hacks like WP Smartcrop plugin: https://plugins.svn.wordpress.org/wp-smartcrop/trunk/wp-smartcrop.php
See capture_attachment_id method for details.

The patch doesn't change the default crop behaviour, but makes cropping functionality extendable.

Attachments (1)

image-resize-dimensions-add-attachment-id.patch (8.7 KB) - added by arkimedia 6 years ago.
Image Resize Dimensions Attachment ID Patch

Download all attachments as: .zip

Change History (4)

@arkimedia
6 years ago

Image Resize Dimensions Attachment ID Patch

#1 @joemcgill
6 years ago

  • Version trunk deleted

Thanks for the suggestion and patch, @arkimedia.

I'm curious what some of the use cases are for wanting to modify this behavior based on specific images and if some of those use cases would be better served by creating subclasses of the image editors themselves?

This ticket was mentioned in Slack in #core-media by joemcgill. View the logs.


6 years ago

#3 @arkimedia
6 years ago

I'm building a plugin which allows admins to select a focal point of an image. Plugin stores focal point data to attachment metadata and uses image_resize_dimensions filter to calculate best cropping area for each image size.

Currently I've used a editor subclass, but filter would be better alternative, because it makes possible to implement solution that works with every image editor class.

And even I'd use subclass, currently the attachment ID won't get passed to the multi_resize method of the image editor class, so I have to resolve the ID from the image path, which has some performance downsides. https://github.com/WordPress/WordPress/blob/71cf332e6569f0ac2f263ce9b2168644942f5534/wp-admin/includes/image.php#L145

In other words passing the attachment id to the multi_resize method is minimum requirement, but passing it to the image_resize_dimensions filter makes possible to implement image editor independent solution.

Last edited 6 years ago by arkimedia (previous) (diff)
Note: See TracTickets for help on using tickets.