PHP + GD + Thumbnails

Discussion in 'PHP' started by chopsticks, Jan 30, 2007.

  1. #1
    I'm sure this can be easily done but I haven't really worked with GD in the past much so i'm not entirely sure. Anyway, i'm curious about thumbnail creation. What I want is a square thumbnail to be created instead of one taking the same proportions of the full size image.

    Basically for example an image of 800x600 is used, instead of a thumbnail of 200x150 created I would like one of a size such as 100x100 instead.

    Anyone have any ideas?
     
    chopsticks, Jan 30, 2007 IP
  2. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I suggest going the Imagemagick 'convert' way, it's a lot better (at least, for me) - you just need to install Imagemagick and call it from within your PHP script:
    shell_exec("convert original_file.jpeg -thumbnail 100 thumbnail.jpeg");
    PHP:
    http://www.imagemagick.org

    HTH, cheers! :)
     
    picouli, Jan 30, 2007 IP
  3. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #3
    rays, Jan 30, 2007 IP
  4. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Thanks for the link, but the problem is i'm on a shared server and I don't have access to it.

    I have been referring to the manual and i'm not really looking for a ready made class. Alot of the tutorials and classes I have found and read don't seem to cater for what I want with the miniture image of 100x100.
     
    chopsticks, Jan 30, 2007 IP
  5. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #5
    picouli, Jan 30, 2007 IP
  6. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #6
    I discovered that just before you post, but thanks anyway. :)

    I've put it in a little class file I have created and now i'm wondering of a more efficient way of creating the small 100x100px image. At the moment I shrink the image to a size where the smallest dimension is shrunk to 100px whilst the largest is kept in proportion with that. From that the 100x100px image is created where it a section from the exact center is taken and used.

    The problem with that method is an image is unnecessarily created wasting resources for nothing. Maybe i'm a little blind or something, but does anyone have an ideas of how it can be done without creating 2 images, instead just a single image?
     
    chopsticks, Jan 31, 2007 IP
  7. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #7
    picouli, Jan 31, 2007 IP
  8. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #8
    Barti1987, Jan 31, 2007 IP
  9. chopsticks

    chopsticks Active Member

    Messages:
    565
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #9
    That's what i've been using. I create a smaller version of the image, and then create a small 100x100 section from that. But 2 images are being created by php when I should really only be creating 1.

    I'm pretty much just curious for basically... the user gives an image of 400x200 and that is shrunk down to 200x100px (smallest dimension is shrunk down to 100px) and then a section of 100x100px is taken from that, so starting 50px from the top and 0px from the left. Thats what I want, but using less resources that what I currently use.

    Thats because if I do it that way it won't be too good for the server when my site goes live and there are tens, maybe hundreds uploading upto 10 images at a time to have to all processed by the server 2 times each.
     
    chopsticks, Jan 31, 2007 IP