Multiple Image Sizes + Cropping

I posted a thread about having zenphoto generate multiple and varying image sizes, and I can see that this only used the width value. Is there a way to have a height value specified also, so that the new generated size is cropped as well?

Thanks for you help.
«1

Comments

  • trisweb Administrator
    Not possible yet... hopefully I'll add that feature soon. If you really want it, you could add a couple more parameters and do the image manips if you know how...
  • Damn. I don't actually know how. Can you show me or is that too much to ask?
  • trisweb Administrator
    Yeah, if I did that I might as well implement it.

    I might just do that before the next version, so hold your horses ;-)
  • Thankyou. I really appreciate it. I think it would be a wonderful feature. I'm looking forward to it. (no pressure though)
  • Can I just check the progress of this? I do/ did not expect this to be done at the drop of a hat, but I was wondering if it will be done and if a possible timeframe could be given.

    I don't mean to be rude, I am just being direct. I need to have this functionality for a project and I would like to know if I should 'try' and do it myself, have someone else do it, or hold my horses a little longer.

    Thanks for your time.
  • This is another function I'd be very grateful for as well - sounds perfect for something I've been trying to do myself for ages.
  • trisweb Administrator
    Hahaha, so there is pressure ;-)

    Alright, I think I can do it right now. Not going to release though. I'll post a link to the latest in SVN once I'm done.
  • trisweb Administrator
    If you come back...

    Do you need the capability to specify the position of the crop? Eg: resize image to 800x600, then take a 400x400 crop from (x,y) position (150, 100) ?

    If not, I'll assume center.
  • --
    If you come back...
    --

    There is no question that I will be back. I love this application and will continue using it for a long time yet. I just need/ed this done and was going to go elsewhere to have this feature implemented. Nothing at the moment could drag me away from this app.

    Back to the question. It would be nice to be able to specify the crop region, if that is possible.

    Can you tell me when it is avaible in SVN if you do it.

    I hope you did not take it the wrong way. I really appreciate the work you do on this and am very thankfull to have such a wonderfull application at my displosal.

    Thanks again.

    EDIT: I saw that you would post a link when you were done. Sorry. I did not read that part.
  • trisweb Administrator
    Nathan, don't worry about it, I have been wanting to do this for a long time.

    It's very easy to allow specification of the crop region, so I'll add that.

    Seriously, I'm not taking it the wrong way :) I understand and I'm happy to help. Why else would I be doing this? ;-)
  • trisweb Administrator
    It's in SVN, but it's not quite usable yet. Browse it here:
    http://svn.berlios.de/svnroot/repos/zenphoto/trunk/

    The files you need to update are:
    - i.php
    - config.php.example (just for line 58)
    - functions.php

    There may be problems because of other changes, in which case you should just grab the whole thing. It's pretty stable at the moment.

    Right now, the options are only available to the URL, not through mod_rewrite fancy paths, but here's an example of the parameters:

    i.php?a=albumname&i=image.jpg&s=640
        &cw=400&ch=300&cx=200&cy=100

    s = size (of the longest side of the image if `conf['image_use_longest_side']` is true, otherwise it's the exact width. Sorry, I'll try to add specific height later)
    cw = crop width
    ch = crop height
    cx = crop offset x (from top-left)
    cy = crop offset y
  • Wow. I can't say I was expecting it so quickly. Well done.
    So, it won't work with mod_rewrite? I don't mind. Not yet anyway.

    I will give it a go and see how it handles. Thanks so much for this.
  • Okay. I gave it a whirl, but I am having a few trobules with it. I think it is just because I am not doing it correctly, not that there is a problem with your code/method, as your example works perfectly.

    Oh, I am using the latest SVN from trunk by the way, so I updated ALL the files.

    My problem:
    - I wish for zenphoto to generate 3 different sized images AS WELL as the thumbnail and scaled/ cropped version in the preview.
    - I input an insanely large format image into zenphoto. It generatd both preview and thumb correctly.
    - Using the above code, how do now generate the following image sizes?:
    • 1024x768
    • 1600x1200
    • 1680x1050
    An example of how to generate one of these images would be appreciated, if they are all the same.

    Again, thanks for this.

    EDIT: The original photo/image zenphoto has is actually the largest sized image (1680x1050) in this case. Thought you might need to know.
  • trisweb Administrator
    Weeeeel, since the 1680x1050 image has a very weird aspect ratio, you actually won't be able to get a 1600x1200 crop from it without upsampling (making the image larger). Zenphoto won't do this as it degrades the quality of the image considerably.

    You can make any size less than 1680x1050 though.

    `i.php?a=albumname&i=image.jpg&s=1228

    &cw=1024&ch=768`

    I had to calculate that 1228 width by hand... so I see why you need to be able to specify height. Otherwise it's just a matter of making it wide enough so it's high enough to get the crop you want. The final image size is going to be cropped from this aspect ratio original, so use cw and ch to specify the crop. You can also fine-tune the position with cx and cy.

    Bottom line though, if you want it to resize up to 1600x1200, I won't put that in the official release. You have to remove a few lines in i.php... just comment out the if statement after this comment:
    `// If the requested image is the same size or smaller than the original, redirect to it.` and that'll let you make images bigger than the original. Be warned though, you're losing quality...

    I'll add the ability to specify height or width directly soon, until then calculate the s value needed from trial and error or the aspect ratio.

    Edit: It's also important to see that you don't need to generate image files beforehand at all. The image doesn't have to be generated to be viewed, and it's all done on the fly, so using this i.php?... stuff is exactly the same as using a real image's URL. You can just throw around that URL like an image; put it in <img src="" /> tags and everything.

    So I hope you're not confusing the image generation with other programs' methods... it's a lot slicker than that.
  • Woah, thats kinda cool. Watch out flickr! Works like a charm
  • They are weird aspect ratios as they are widescreen images. For the moment, I would like to keep this ratio as that is what the larger/ wide screens demand.

    I could always give zenphoto a larger image if necessary. All the images are illustrator vector files, so they can be any size really.

    I'll comment out the line and see what happens, but I think I might hold off for the specific height. I don't really want to loose quality.

    Oh, and I know that all those images are generated on the fly. It is a wonderful system and now I don't (well, there are still a few issues to sort out first) all the different file sizes on the server. It can make them for me.
  • Hey folks, been away else woulda commented earlier - BIG THANK YOU for adding this so fast, look forward to test it out. Cheers :D
  • 3stripe, it works really well, but, in my instance, I am having a little trouble with it. I have weird ratios that need to set a specific height with my width.

    trisweb, is it difficult to have zenphoto generate images based on a width AND a height? I mean, is it a lot of work, or something that can be implemented in a night or so.
  • trisweb Administrator
    Nope, I'm definitely going to take care of that soon.

    The problem is a matter of cropping or resizing out-of-proportion... so you're saying you'd like to resize it and crop it down? Or just specify a width and height and resize to that, losing the aspect ratio (distorting the image)? I think I'll make both available anyway, but I'd like to know what you're trying to do...
  • I want to CROP it to the new aspect ratios, instead of simply resizing it. I don't want distorted images, but I do require them in the different (obscure) sizes, so resizing AND cropping of the image is required for my purposes.

    You can see what I mean with the image sizes that I need to generate. I posted those a few comments ago.

    Thanks for keeping me informed of your progress and for keeping an interest in this discussion.
  • trisweb Administrator
    The latest in SVN should do what you want.

    Use the new template functions... look for them in the php file, or in the updated stopdesign theme, which is now checked into SVN (shh ;-). Also look at the comment at the top of i.php for full documentation on the URI parameters.

    What you'll want is to use either ?h=768 or ?w=xxx and then crop the other dimension. In your case, fixing the height is the way to go. So like, `i.php?a=album&i=image.jpg&h=768&cw=1024` will get you a 1024x768 image with the sides cropped off. You can then play with &cx=n to adjust the crop position if you can work out a way to do it for each image... (that's something I'm working on ;-)

    And this is fun stuff. Probably my favorite part of this project. It allows for a lot of power and opportunity to streamline, so it's fun to program. :-) Thanks for using it.
  • No, thank you for making it. I will give it a quick go tonight (now) and let you know how it all works.

    I can't see why it wouldn't.

    Thanks again.
  • Right. This version of trunk is not the most stable of versions. Can I replace the following files in a stable release and have the functions work?:
    - i.php
    - config.php (well, its new name)
    - functions.php

    I can't see why that would not work.
  • trisweb Administrator
    Not the most stable? Please, do tell... It's quite stable for me; the main problems you're seeing are probably config changes -- fill out the new zp-config.php file instead of your old config.php and it should work fine...

    And no, you can't just bring in the new files; they're dependent on some of those config changes. They're good changes, so it's worth it, trust me. :)
  • Okay. It all works. Thank you.

    I do however have 1 more request (please don't hate me :-P ).
    I would like to do all of this dynamically, and I was wondering if there are any, or if you can add some functions to at least get the following.
    - album name (i.e. desktops)
    - image name (i.e. image.jpg)

    I was using (before all the cropping came into it all) the `getSizedImageURL` function, but this only supports the `s` value.

    As I am generating all the images on the fly for every desktop picture I have, I can't (and don't want to) hard-code the image links into the template.

    Can I make a final request, where I can have a function that allows me to parse all the values, or, a few little functions that will allow me to procude a link like the following:
    `i.php?a=<?=getAlbumName;?>&i=<?=getImageName;?>h=768&cw=1024`

    I am generating the same sized images all the time, so I would place that link, or something like it in the/a template file. That way, with every image, I have the selection/links to download the other x (in my case 3) image sizes.

    I hope that made sense. And I am sorry to do this to you once again.

  • Not the most stable? Please, do tell... It's quite stable for me; the main problems you're seeing are probably config changes -- fill out the new zp-config.php file instead of your old config.php and it should work fine...

    And no, you can't just bring in the new files; they're dependent on some of those config changes. They're good changes, so it's worth it, trust me. :)
    The problems are not for this thread. I will open up another one. It is basically what you described, especially with the setup of app.

    Sorry for the double post (again). I only just got it.
  • trisweb Administrator
    Right, so just use the image loop, like in any of the themes (use one as an example) and for each image, print out its link using the getCustomImageURL(...) function. That part's easy, and I thought you knew that already ;-) Just look at the themes, all the loops are set up. You don't need to "get" the album or image names, hehe :)

    Your getCustomImageURL would look something like...

    `getCustomImageURL(null, null, 768, 1024)`

    The first two are $size and $width, which you don't want, so keep them null. This would go in the image loop, and would produce links to those sized images for each image in the album.

    Hope this helps! I really should put up some better documentation so this stuff makes more sense...
  • Ah. I see. I did NOT update to the latest SVN. I managed to get it working on the other build. My fault. Sorry to bother you with that. I did not see that function there.

    All working now.
  • trisweb Administrator
    Excellent. Can I see what you're doing with it? I'm imagining some kind of wallpaper site...
  • For sure you can see. It is local for the time being, but as soon as it goes live, I'll put a link up here.
Sign In or Register to comment.