SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Resizing an image with PHP

    Hi,

    In my application, I need to change the dimensions of an uploaded image. I did some research and learned that it was possible with the GD extension. I was wondering if there is another way which doesn't require an extension.

    Thanks for any ideas.

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,369
    Mentioned
    80 Post(s)
    Tagged
    3 Thread(s)
    What is you reason for not using GD; It has been included in php for years.

  3. #3
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SOLVED I revised my code using jQuery and I don't need image resizing anymore, found an alternative way to accomplish what I wanted.

    Quote Originally Posted by Rubble View Post
    What is you reason for not using GD; It has been included in php for years.
    The reason is that this is an application that will be distributed and I didn't want "You should have GD extension enabled" type of requirement in my application.

  4. #4
    SitePoint Guru bronze trophy
    Join Date
    Dec 2003
    Location
    Poland
    Posts
    930
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    If you don't want an extension then you can use ImageMagick if it is installed on the server, then you can run ImageMagick's commands (convert, mogrify, etc.) directly with exec() in php. Many hosts have ImageMagick installed, some don't. There's also Imagick php extension for using ImageMagick so that is also an option if it's installed.

    I always use ImageMagick for image resizing and manipulation in php - in comparison with GD it creates better quality images, has more features, it's faster and doesn't choke on large images. Nowadays so many hosts offer ImageMagick that it's not a problem at all - unless you want to make a distributed library for others to download and it needs to work on as many platforms as possible.

  5. #5
    SitePoint Guru bronze trophy
    Join Date
    Dec 2003
    Location
    Poland
    Posts
    930
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nayen View Post
    SOLVED I revised my code using jQuery and I don't need image resizing anymore, found an alternative way to accomplish what I wanted.
    I hope your jQuery solution is not resizing images in the browser. Sometimes I can see web galleries where small thumbnails are actually large images that are made smaller in the browser by changing <img> dimensions - such pages are slow to load, waste bandwidth and often the quality of the small thumbnails is not very good.

  6. #6
    SitePoint Addict
    Join Date
    Nov 2009
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Lemon Juice View Post
    If you don't want an extension then you can use ImageMagick...
    Thanks for your detailed reply. If I ever need image resizing on my own website, I will most probably use it but as I said above, this application will be distributed and I can't have GD or ImageMagick as a requirement. I just wanted to know if there was another PHP way and it seems not.

    Quote Originally Posted by Lemon Juice View Post
    I hope your jQuery solution is not resizing images in the browser. Sometimes I can see web galleries where small thumbnails are actually large images that are made smaller in the browser by changing <img> dimensions - such pages are slow to load, waste bandwidth and often the quality of the small thumbnails is not very good.
    There is only one image in one certain section that is resized so even if it is resizing in the browser, that will not be a problem.

  7. #7
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,039
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Can't you just check if GD is available and if so use it, otherwise use the jQuery plugin? GD will be available most of the cases, making for a much nicer solution IMHO.
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


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
  •