Opened 18 months ago
Last modified 6 weeks ago
#19393 new enhancement
Image crop position
| Reported by: |
|
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)
Change History (38)
comment:3
in reply to:
↑ 1
DrewAPicture — 18 months ago
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.
comment:10
tammyhart — 16 months ago
- 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
dwenaus — 16 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?
comment:12
jane — 16 months ago
- 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
azaozz — 16 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.
comment:14
goto10 — 16 months ago
- Cc dromsey@… added
comment:15
in reply to:
↑ 13
bradt — 15 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.
comment:16
ryan — 13 months ago
- Milestone changed from 3.4 to Future Release
comment:17
brasofilo — 12 months ago
- Cc brasofilo@… added
comment:18
pauldewouters — 12 months ago
- Cc pauldewouters added
Related: #15989
comment:20
sillybean — 10 months ago
- Cc steph@… added
comment:21
sabreuse — 10 months ago
- Cc sabreuse@… added
- Cc philip@… added
comment:23
Viper007Bond — 9 months ago
- Cc Viper007Bond added
comment:24
scribu — 8 months ago
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.
comment:26
navjotjsingh — 8 months ago
- Cc navjotjsingh@… added
comment:27
mordauk — 8 months ago
- Cc pippin@… added
comment:28
sc0ttkclark — 8 months ago
- Cc lol@… added
- Cc LisaSabinWilson added
comment:30
ethitter — 8 months ago
- Cc erick@… added
comment:31
scribu — 7 months ago
Related: #22100
comment:32
richardmtl — 6 months ago
- Cc richardmtl added
comment:33
alexvorn2 — 6 months ago
- Cc alexvornoffice@… added
comment:34
lkraav — 6 months ago
- Cc leho@… added
comment:35
SergeyBiryukov — 4 months ago
#23161 was marked as a duplicate.
comment:36
glueckpress — 4 months ago
- Cc caspar@… added
comment:37
markoheijnen — 6 weeks ago
- 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 :)

Swoon.