Results 1 to 5 of 5

Thread: Resize/create image

  1. #1
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default Resize/create image

    Does anyone know how I can resize, and create new image with php? I want the first image to only be resized if it is greater than 600 pixels wide and the second image to be the same image but 110 pixels wide and have a _tmb after the name but before the extension.

    I found this http://www.white-hat-web-design.co.u...e-resizing.php but it doesn't work even if I copy it straight over with no changes. I don't know if it's only for a specific version of php or something else but I don't see much documentation on it either; so if anyone knows something better that'd be great. Thanks.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You have to use the GD library or imagemagick (which is not part of the default installation for PHP).

    You simply calculate the size of the image and determine if you want it to change, then do some basic math to keep the ratio the same, assuming you don't want to distort it, and apply an image function from one of the two libraries, and output the image.

    Here's a place to start:
    http://www.php.net/manual/en/functio...opyresized.php
    The example script is basically all you need.

    Be warned, though, the image functions in PHP are slow, resource intensive (I've gone over allowed processor usage once or twice with big images), and they can be difficult to use for complex processes.
    It's always best to limit your use of them to as few images as possible and always keep the images reasonably small-- using this to resize large photos may be a bad idea.
    Also, never perform the same calculation twice, so find a way to cache the thumbnail/etc once you have created it (basically save it to a folder and then next time see if that image exists-- if so use it, else create/save the scaled image from the original).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. The Following User Says Thank You to djr33 For This Useful Post:

    bluewalrus (10-29-2009)

  4. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    I use GD library and ImageMagick together to resize images when they are uploaded to my site so that the original image is stored in one folder and the thumbnail version is stored in another folder, much like you describe. I recently went through a lot of my anime reviews updating the screenshots to higher quality images and I would upload 6 "full sized" images at a time to be formatted. I spent two full days going through my dvds and uploading the images.

    Another program, which is just for fun will take an image and randomize the colors or alter it it in many of the ways that can be done utilizing the GD library. There is also a reset button for the image as well.

    Lastly, I have a program that will generate a rounded corner for my articles which is small and has the appropriate foreground and background colors.

    The question is how intensive do these programs need to get before you get in trouble with your website host for doing something that is too processor intensive? To be honest I am the only one that can and does utilize these programs with the exception of the one that I created just for fun, but I doubt many people are even aware of that one.
    To choose the lesser of two evils is still to choose evil. My personal site

  5. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Thanks I did't know I need a library upon going into my server I found a pear package that looks like it does this as well. I'm going to test it out later though got back up with some other stuff.

  6. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Note: GD does come installed with PHP in almost all packages; it's not necessarily part of the core of PHP, but it's always there. Imagemagick is something you must go find/install yourself (not that it's hard to find, etc.).
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •