Opened 18 months ago

Last modified 6 weeks ago

#19393 new enhancement

Image crop position

Reported by: bradt Owned by:
Priority: normal Milestone: Future Release
Component: Media Version: 3.3
Severity: normal Keywords: needs-patch
Cc: joachim.kudish@…, kontakt@…, deryk@…, miklb@…, jeremy@…, anointed, tammyhart, dromsey@…, brasofilo@…, pauldewouters, steph@…, sabreuse@…, philip@…, Viper007Bond, navjotjsingh@…, pippin@…, lol@…, LisaSabinWilson, erick@…, richardmtl, alexvornoffice@…, leho@…, caspar@…

Description

In WP, images are cropped to center horizontally and vertically. Setting a different crop position is very painful and a bit of hack using filters/hooks (see https://gist.github.com/1405838). The small attached patch enhances the $crop parameter of add_image_size, allowing an array to be passed in containing the crop position. For example,

add_image_size( 'product-screenshot', 300, 300, array( 'left', 'top' ) );

The $crop parameter still accepts true/false values and the patch should be fully backward compatible. Syntax is borrowed from CSS' background-position property, so it should be familiar to designers/developers.

Attachments (1)

wp-image-crop-position.patch (2.7 KB) - added by bradt 18 months ago.

Download all attachments as: .zip

Change History (38)

comment:1 follow-up: ↓ 3   nacin18 months ago

Swoon.

  • Cc joachim.kudish@… added

comment:3 in reply to: ↑ 1   DrewAPicture18 months ago

Replying to nacin:

Swoon.

Indeed.

  • Cc kontakt@… added

This isn't in the scope of this patch, but it might be a good thing for down the road: It'd be great if you could identify a scope for image sizes, as well. For example, we have a 250x250 thumbnail size, but also a 75x75 thumbnail size. If you crop only the thumbnail, the 75x75 size doesn't crop with it. Then when cropping, instead of selecting "thumbnail" or "all other image sizes," you could select a scope.

  • Cc deryk@… added

double swoon

  • Cc miklb@… added
  • Cc jeremy@… added
  • Cc anointed added
  • Cc tammyhart added

Besides on the fly cropping, this is the one thing that I hated about dropping Tim Thumb. Changing the position really helps with things like website screenshots where you want the logo/header to be in the crop, not a chunk out of the middle. The filter/hook hacks work great, but I would love to see this in core.

comment:11 follow-up: ↓ 13   dwenaus16 months ago

there are many times when you have pictures of people, and cropping to the middle chops off their head. uncool. :) is this going to make it into 3.4?

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 3.4

I would say this falls under editor/media improvements and should therefore be looked at by @azaozz.

@bradt and everyone: Don't forget to add the has-patch keyword when you post a patch, or the appropriate leads won't know to look it over.

comment:13 in reply to: ↑ 11 ; follow-up: ↓ 15   azaozz16 months ago

Replying to dwenaus:

there are many times when you have pictures of people, and cropping to the middle chops off their head. uncool. :) is this going to make it into 3.4?

Thinking this would need more general solution. Currently users can crop the images (or just the thumbs) any way they like by using the image editing tab in the image settings.

Similarly we have two sets of image manipulation functions: one "general" and another specific for the image editor. Imho it's worth merging them and making a nicer API for image manipulation in core.

  • Cc dromsey@… added

comment:15 in reply to: ↑ 13   bradt15 months ago

Replying to azaozz:

Replying to dwenaus:

there are many times when you have pictures of people, and cropping to the middle chops off their head. uncool. :) is this going to make it into 3.4?

Thinking this would need more general solution. Currently users can crop the images (or just the thumbs) any way they like by using the image editing tab in the image settings.

Are you saying that every time a user uploads a headshot, screenshot, or any other image that requires a different crop position, we should expect the user to go into the cropper tool and crop the image and/or its thumbnails? I don't see any reason why we shouldn't be able to set a different default crop position for each image size and save the user this hassle. I can tell you first hand that when the user is a client, this is a tall order.

Similarly we have two sets of image manipulation functions: one "general" and another specific for the image editor. Imho it's worth merging them and making a nicer API for image manipulation in core.

Agreed, but I believe it's outside the scope of this patch. This patch is about extending the $crop variable of the the add_image_size API function to solve a common problem where the top solutions found on Google has long been to *gulp* ...hack the core.

  • Milestone changed from 3.4 to Future Release
  • Cc brasofilo@… added
  • Cc pauldewouters added

Related: #15989

Last edited 10 months ago by SergeyBiryukov (previous) (diff)
  • Cc steph@… added
  • Cc sabreuse@… added
  • Cc philip@… added
  • Cc Viper007Bond added

Awesome idea. Related: #21810

If the intval() casting in wp-admin/includes/images.php weren't there (as per existing patch) the rest of it could be done via a plugin or theme's functions.php implementing the image_resize_dimensions filter ... no?

I wouldn't mind stripping the casting and calling the rest plugin/theme territory.

  • Cc navjotjsingh@… added
  • Cc pippin@… added
  • Cc lol@… added
  • Cc LisaSabinWilson added
  • Cc erick@… added

Related: #22100

  • Cc richardmtl added
  • Cc alexvornoffice@… added
  • Cc leho@… added

#23161 was marked as a duplicate.

  • Cc caspar@… added
  • Keywords needs-patch added; has-patch removed

Remove has patch since the changes of 3.5 but would be cool to add this in 3.7 :)

Note: See TracTickets for help on using tickets.