Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Resizing images without saving

    Hi Guys,

    on a members profile, i have the "viewimages" section, you can go in and see all the images the user has uploaded, what i was going to do is show them all as 1 size say "300x300" then when the user clicks the "View Fullsize" button the original size pops up, all fairly easy to setup, only im not sure how to just resize the images, i don't need thumbnails or anything, is there a way i can do this with GD or even imagemajick as i have both installed.

    thanks guys

    Graham

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,502
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    You can use GD to resize images on-the-fly. You didn't mention how
    many images and how many page accesses you'll have each month.

    GD resizing does take processing time and consumes server load.

    Someone else can interject on this, but I think it would be more efficient
    to save a duplicate image that's 300X300 at the same time the user
    uploads the image ... perhaps in a directory called "cache". That way,
    GD only runs the one time (when they upload the image) ... not 1000
    times a month when people view the image(s).

    So the trade-off is using disk storage to keep those cached images VS
    using GD to display them on-the-fly. I think the disk storage is cheaper
    and faster than the processor time.

    =====

    When they upload the image, you do your normal upload thing, and at the
    very end, before you redirect back, you run a PHP (GD) script to use the
    uploaded image (imagecreatefromjpg) resize it, and save into the other
    directory called "cache" (or whatever you call it).

    You could also do something where you check for the image in "cache" and
    if it does not exist, you do the PHP GD thing to create it. Once created,
    it will exist the next time someone wants to see it.

    If the member deletes their photo in their own directory, you also "unlink"
    the cached photo, because they will have the same exact filename, but
    different directories.


    That's my 2 cents.

  • Users who have thanked mlseim for this post:

    graham23s (11-20-2007)

  • #3
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    That sounds like a very good solution.

    To that I would add that you set up a cronjob that deletes cached images (past a certain age) at a specific interval, so that it does not grow too big.

  • Users who have thanked aedrin for this post:

    graham23s (11-20-2007)

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Location
    Scotland
    Posts
    134
    Thanks
    12
    Thanked 0 Times in 0 Posts
    thanks a ton guys thats exactly what ill do i think.

    thanks again

    Graham


  •  

    Posting Permissions

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