Hi,
I was wondering if it's possible to crop only the longer side of a thumb to a specific length after resizing. For e.g. if I have a panoramic picture that is 2048x768 in size, and I specify a thumb size of 85 in the config. The pic would get resized to 227x85. So far so good. But in my gallery, I don't want thumnbails that are more than 130px wide or tall. Now, I can't specify a crop size of 130 in the config because that's not what the property's used for. Hence, I wonder if such functionality is possible or will be included in zenphoto?
Thanks.
Comments
I made a function to do a "fitFromOutside" type scaling of an image to a given rect. This basically scales down an image until either of its opposing edges touches the matching edges of the rect I want it to fit. ( the 'max space' functions, I believe, are equivalent to "fitFromInside" )
This means that there's often extra space left which needs to be chopped off. Using getCustomImage() seems like it should do the trick, but this code...
`$img->getCustomImage(null,130,68,90,68,20,0)`
...results in an image that is 130x86 pixels. I would have expected the result to be a 90x86 pixel image, cropped -from- the 130x86 pixel image, with the crop started 20 pixels from the left (a bit superfluous as I think the crop always defaults to the center of the image - removing cx and cy didn't change anything, however).
What am I missing? Probably something simple, but the documentation for the getCustomImage method in the Image class is fairly bare. e.g. it doesn't specify behaviors . I peeked at the code and it certainly -seems- like it should be cropping down to the size specified if all goes well, so I'm not sure where it's not going well
( getMaxSpaceContainer is the core function they all rely on, I believe )
I did look at i.php , which is what I was basing my expected behavior on;
` * s - size (logical): Based on config, makes an image of "size s."`
Not using that one, set null.. This means I must specify w, h, or both w and h.
` * h - height (explicit): Image is always h pixels high, w is calculated.`
I'm specifying this as 68 pixels. Note that although the description states that w will be calculated, this is only true if w is not supplied.
` * w - width (explicit): Image is always w pixels wide, h is calculated.`
I'm specifying this at 130 pixels. The same comment applies here. ( In addition, perhaps the w and h lines should be swapped, as the other parameters are in order of horizontal, then vertical, appearance as well ).
So far so good, this should give me the image resampled to 130x86 pixels.
` * cw - crop width: crops the image to cw pixels wide.`
Here's where a bit of confusion sets in. It states that it crops 'the image', but does it crop the image -before- the resize, or crop the resized image -after-? Logically (to me, especially given that the above definitions referred to 'Image' as being the result of the w and h parameters) it would be after. So I dug a little further.. the first deep call that does the actual magic is:
`zp_resampleImage($newim, $im, 0, 0, $cx, $cy, $neww, $newh, $cw, $ch)`
which in turns calls the GD function
`imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);`
Which appears to imply that you're not so much cropping the result, as 'pre-cropping' (specifying the source image 'window' to work with) the image before resizing.
So therein will probably lay the problem I was facing - and should be able to fix my function now >_< .