Make WordPress Core

Opened 5 years ago

Last modified 5 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:


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:
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 5 years ago.
Image Resize Dimensions Attachment ID Patch

Download all attachments as: .zip

Change History (4)

5 years ago

Image Resize Dimensions Attachment ID Patch

#1 @joemcgill
5 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.

5 years ago

#3 @arkimedia
5 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.

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 5 years ago by arkimedia (previous) (diff)
Note: See TracTickets for help on using tickets.