Problems with custom thumbnails and crop positions

Megan Member
Hello,

I just upgraded from Zenphoto 1.1.5 to 1.2.4. Everything seems fine except for the custom functions I was using to generate thumbnails in the old version. These are the functions I'm using:

On the index:
`<?php printCustomAlbumThumbImage(getImageTitle(), 180, 180, 180, 180, 180, 0, 10); ?>`

On the album pages:
` <?php printCustomSizedImage(getImageTitle(), 150, 150, 150, 150, 150, 0, -10, null, null, false); ?>`

These work fine in 1.1.5 but in 1.2.4 the thumbnails are really weirdly distorted and stretched out. Any numbers I put in for the crop positions seem to cause the same problems.

Here's my gallery:

http://pole.uwaterloo.ca/cpadev/news/gallery/Research/

Also, a few questions about the parameters in these functions:

What exactly does "size" mean? How is this used in relation to the height and width dimensions? And the crop dimensions? I'm confused about why the numbers I used get the results I they did.

Does cropping really start at the top-left corner? Because it looks to me that it's centered on the image (e.g. I have 180px images with a 150px crop - the crop takes off about 15 pixels on either side, rather than 30px at the bottom/right). If this is the case, then where are cropx and cropy measured from?

Do these parameters override the settings in theme options?

Thanks for any help.

Comments

  • size is an altenative to height/widht. You should not have all three items set. In your case, height/width should probably be NULL since you seem to want a 180x180 image.

    first the crop is done by taking a slice of the image from (cropx,cropy) to (cropx+cropw,cropy+croph) then the result is resized to fit either size or height x width. If cropx or corpy are not given then the value used is 1/2 the "trimmed" area. In other words if both are not provided, the crop is centered on the image. Zero is, unfortunately, the same as not provided due to the foibles of PHP. You would have to use 1 i you want the edge of the image.

    The parameters override any settings. More to the point, there are no theme settings for the custom functions.
  • Megan Member
    Thanks a lot, that's a big help. I'm in the middle of working with this now. Currently I'm using this:

    ` <?php printCustomSizedImage(getImageTitle(), 150, null, null, 15000, 15000, 1, 1, null, null, false); ?>`

    Which gets me something resembling a normally scaled image, although they are being scaled on the long side instead of cropping.

    The question is: why in the world did I have to go up to 15000 for the cropw and croph to get a normal section of the image???

    Does the Stop Design theme work okay for others? For me it has the same problems I was having originally.
  • acrylian Administrator, Developer
    If you want cropped images you should not set the $size parameter. This is for uncropped images only (depending on the admin setting by longest side etc). Try something like`<?php printCustomAlbumThumbImage(getImageTitle(), NULL, 180, 180, 180, 180, 0, 10); ?>`
  • Megan Member
    That seems to be getting me the same result I had when I was using $size...

    So the thumbnails use the admin setting under image size for longest side etc.? Changing that setting doesn't seem to make a difference.
  • Stopdesign is working correctly for me. Maybe a good experiment would be to use the custom thumb cropping in admin. This will store its values in the database. You can then look at the image record in the database and see what values it used.

    Cropw and croph are relative to the full sized image, so yours would have to be 15000x15000 for that to be correct. I doubt they are that large, so there must be someting else wrong.

    At this point I would a clean install of the nightly build. Maybe there are some bad files in your install. (Just a guess, though.)
  • Megan Member
    Ooooooh, so it's cropping from the full sized image! That makes a bit more sense now. These functions take the original image, then crop it to the dimensions specified from the x/y axis specified, then resize to $size or height/width. That probably won't work well for me - some original images may be larger/smaller than others.

    Are all the details about how these parameters work documented anywhere? That would be useful.

    Is there more custom thumb cropping in admin than what's under theme options? (thumb size, crop thumbnails).

    I think the stop design theme is actually working now, dont' know why it was showing the distorted thumbnails before. I notice he's using get custom sized image so maybe I'll try that ... All I'm trying to do is move the crop position up a bit so that peoples' heads don't get cut off in the thumbnails.

    This worked fine for me in 1.1.5 but I think I might have messed around with the zp-core files at the time...
  • Megan Member
    Okay, found a solution. What I needed to do was find the short edge of the image, crop it in a square to that size from the origins specified, then resize. After looking at the stopdesign code, I found out how to find out if it's landscape or not, then put in different printCustomSizedImage functions for each:

    `
    <?php
    if (isLandscape()){ // if it's landscape, just print a normal thumbnail
    $ch = $_zp_current_image->getHeight();
    $cx = ($_zp_current_image->getWidth()/2) - ($ch/2);
    printCustomSizedImage(getImageTitle(), null, 150, 150, $ch, $ch, $cx, null);
    } else { // if it's portrait, set the crop dimensions to match the width of the image
    $cw = $_zp_current_image->getWidth();
    printCustomSizedImage(getImageTitle(), null, 150, 150, $cw, $cw, null, 50);
    }
    ?>
    `
    Not sure why I had to write that formula to get the $cx position for the landscape images... otherwise it was resizing & squishing them.

    New question: isLandscape() and getHeight()/getWidth() aren't available for album thumbs. Is there anything else I could use instead?

    Thanks a million for all your help!
  • The album thumb is actually an image. `$thumb = getAlbumThumb();` Of course you have to use the object methods to get information about the thumb. `$landscape = $thumb->getWidth()>=$thumb->getHeight();`
  • Megan Member
    Okay, when I do that I get an error "call to a member function getWidth() on a non-object". Is there something I'm missing here??

    (sorry about my crappy PHP skills!)
  • Did you use the code above? The error you are getting indicates that the $thumb variable was not setup. I don't really see how that could happen, though.
  • Megan Member
    It's getting a url for the $thumb, it's the getHeight/getWidth that doesn't work. This is what I have right now just for testing:

    `

    <?php<br />
    $thumb = getAlbumThumb();

    echo "

    " . $thumb . "

    ";

    if ($thumb->getWidth() >= $thumb->getHeight()) {

    echo "

    landscape

    ";

    }

    ?>

    `
  • Ok, sorry, my fault. I gave you the wrong function to use. Change `getAlbumThumb()` to `$_zp_current_album->getAlbumThumbImage()` Of course, the `echo '

    '.$thumb.'

    ';` will also need to change since $thumb is an image object. `echo '

    '.$thumb->getThumb('album').'

    '`
  • Megan Member
    That's much better!

    Now for one more small problem:

    When I render the tumbnails using printCustomAlbumThumbImage it's setting the height and width attributes of the `image` to the value of cropx and cropy. In template_functions.php it looks like it's is choosing whichever is higher, width or cropx, and then setting the width="" attribute to that (???). Since cropx is relative to the original image it's going to be bigger than the thumb size. So I get thumbnails that are resized using the height/width attributes to something like 1450 x 1450 (or whatever the size of the original image was).

    I can fix this by changing max to min or just removing the $settings variable from the `image`. It is generating the thumbnails correctly.

    Here's my current function:

    `

    <?php<br />
    $thumb = $_zp_current_album->getAlbumThumbImage();

    if ($thumb->getWidth() >= $thumb->getHeight()) {

    $ch = $thumb->getHeight();

    $cx = ($thumb->getWidth()/2) - ($ch/2);

    printCustomAlbumThumbImage(getImageTitle(), null, 180, 180, $ch, $ch, $cx, null);

    } else {

    $cw = $thumb->getWidth();

    printCustomAlbumThumbImage(getImageTitle(), null, 180, 180, $cw, $cw, null, 50);

    }

    ?>

    `
  • I'll have to look into how to deal with this issue. The sizing is really only needed if there is no album thumb image. In the mean time, just set $sizing to "".
  • Ok, I've made some changes to the development stream to deal with this. Install tonight's nightly for the correction.
Sign In or Register to comment.