ZenphotoCMS Forum
getCustomImage function: Can it do scaling first then cropping? - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: General support (https://forum.zenphoto.org/forum-4.html)
+--- Thread: getCustomImage function: Can it do scaling first then cropping? (/thread-4927.html)



getCustomImage function: Can it do scaling first then cropping? - ppy - 2009-03-29

Hello,

I am using zenphoto 1.2.3[3427]

I have an image which is 1000 x 666 in size. I use getCustomImage function like this:
$image->getCustomImage(null, 900, null, 900,200, null, null).

This will give me a cropped 900x200 image. However, it's cropped from the original image, not the resized 900 width image.

So my question is: is there anyway I can change the order of cropping and scaling? I want it to scale first, then do the cropping based on the scaled image.

Is it possible?

Thanks




getCustomImage function: Can it do scaling first then cropping? - sbillard - 2009-03-29

No, that is not possible. Make your crop based on the original image.




getCustomImage function: Can it do scaling first then cropping? - ppy - 2009-03-30

Thank you very much sbillard.

I realized that after posting this question... All I need to do is to calculate the cropping width ,height and the x, y position.




getCustomImage function: Can it do scaling first then cropping? - ppy - 2009-03-30

I found something strange though.

with my new function, i calculate the cropping width, height, x and y, then use getCustomImage() function. I set the output width to 900. What I found is if the picture size is large (width=3888) the output is perfect. However, if the original picture is just a little bit larger than 900, 1024 for example, the output picture is somehow flattened a little.

I have no idea why.

here's an example from zenphoto's demo gallery:

original picture (595x446): http://www.zenphoto.org/zenphoto/albums/demo-gallery/P4130946.jpg

flattened crop (width=523):
http://www.zenphoto.org/zenphoto/zp-core/i.php?a=demo-gallery&i=P4130946.jpg&w=523&cw=595&ch=132&cy=157

Even I chagne the output width and height to the same as the cropping size, the output is not right:
http://www.zenphoto.org/zenphoto/zp-core/i.php?a=demo-gallery&i=P4130946.jpg&w=595&h=132&cw=595&ch=132&cy=157

if i change the output width to a smaller size,say 400, the h/w ratio of the output is back to normal again:
http://www.zenphoto.org/zenphoto/zp-core/i.php?a=demo-gallery&i=P4130946.jpg&w=400&cw=595&ch=132&cy=157

Is this a bug in the cacheImage() function or in the php processing function?




getCustomImage function: Can it do scaling first then cropping? - sbillard - 2009-03-30

You probably want to specify the size, not the width. If you need to specify the width you will probably need to compute both the width and the height values.




getCustomImage function: Can it do scaling first then cropping? - ppy - 2009-03-30

Problem solved I guess.

I found this post: http://www.zenphoto.org/support/topic.php?id=5188

so if I add cx=1 to the examples above insdead of cx=0 or no cx, the output is fine.