Custom cropped sizes and aspect ratios

Hi, I am needing to have images cropped on the fly based on what resolution the user needs. (it's for a wallpaper site.) Say I have an image that is 2560x1920 but I want to have a link to a widescreen version which would for example be something like 1280 x 800. I need to know what the code would be for this. For an example, I am currently using this `getCustomImageURL($size=1600)` code in the image.php file which outputs on the fly a 1600 x 1200 image from the original. This works fine as the ratio does not change from the original image.

So what I need to know is what to enter between the () that would crop the image to the dimensions I specify--essentially changing the aspect ratio of the image.

Also, I need to specify the offset of the crop so that it will crop an equal amount off the top and the bottom of the image so that I'd have a nice 16:10 widescreen aspect ratio.

Thanks in advance for any help you can provide.

Comments

  • The function parameters can be found in the functions guide http://www.zenphoto.org/documentation/zenphoto/_template-functions.php.html.

    The explaination of the parameters is found at the beginning of the i.php file.
  • kace Member
    Thank you. I have been to that page before and also the i.php and being that I'm new to php and pretty clueless, I have been unable to figure out the correct parameters. I've tried so many different variations and I'm just not getting it to work. (Sorry for being a retard about this.)

    Could you give me an example of the code I would need to resize a 2560 x 1920 image to 1280 x 800? I can't seem to get it to crop it both sides. I end up with it resized to the 1280 width but not 800 height.

    This is the code I figured would work, but just changes the width: `<?php echo getCustomImageURL($cropw=1280, $croph=800);?>` Obviously it is not the correct code to use... what am I doing wrong? Thanks! :)
  • When you pass parameters to a function in PHP they are passed by position. So your code above set two local variables to 1200 and 800 then passed these as the size and width parameters to `getCustomImageURL`. The call should be `getCustomImageURL(NULL, 1280, 800);` If you want also to crop the image you would pass those parameters as well `getCustomImageURL(NULL, ,NULL, NULL, 1280, 800, xcoordinate, ycoordinate);`

    A good practice if you are new to something like this is to do a search on the zenphoto files for uses of the function to have examples of how things are used. This particular function is used in the effervescence+ theme. There is also `getCustomImage` which is a similar function and has the same parameters. It is used in effervescence+ and stopdesign.
  • kace Member
    Thank you! I love learning about this. I finally got it right and this is the code that works for me: `getCustomImageURL(NULL, 1280, NULL, 1280, 800, NULL, NULL)` I'm not sure exactly how I came up with that but it works like a charm and crops it in the right places. I am using the stopdesign theme and have poked around various themes and files to learn how different functions work from examples, but your example above is what helped the most. Thanks again, I really appreciate it!
Sign In or Register to comment.