Problem uploading and resizing images

Discussion in 'PHP' started by Philopoemen, Jan 27, 2008.

  1. #1
    Hi there,

    I have a community where users can upload personal avatars.
    Most images work fine (i accept .gif and .jpg/jpeg).

    My function resizes the uploaded avatar to 2 different sizes, and saves in a directory these 2 new files.

    However, there are images that for some reason are not accepted. I don't know why. Usually that happens with .jpg files. The only thing that makes them work, is if I save them as (through Photoshop) .gif, and then upload.

    Anyone has this problem?

    Also, if anyone has a very neat class for image handling (uploading, resizing, watermarking), or any links to really great and useful tutorials - i would appreciate it :)
     
    Philopoemen, Jan 27, 2008 IP
  2. Dan3

    Dan3 Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hi Philopoemen,

    what does your actual function look like, and what is the error message, it's hard to tell what the problem is when this info is missing. Anyway, have you taken a look at PEAR? It offers standard library for common functions, including the resize function for images:

    For example, with the PEAR package Image_Transform installed:

    <?php
    require_once 'Image/Transform.php';
    $i =& Image_Transform::factory('');
    
    $i->load('test.jpg');
    $i->fit(100,100);
    $i->save('resized.png', 'png');
    ?>
    
    PHP:
    I am using this and have never had a problem, i am doing the same thing, saving it twice in a dir, one thumbnail, one original.

    For the uploading, i would recommend the PEAR package HTTP_Upload.

    http://pear.php.net/package/Image_Transform
    http://pear.php.net/package/HTTP_Upload
     
    Dan3, Jan 27, 2008 IP
  3. Philopoemen

    Philopoemen Peon

    Messages:
    704
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey Dan,

    Does this package handle any type of image? .png, .gif, .jpeg?
     
    Philopoemen, Jan 28, 2008 IP
  4. neds75

    neds75 Peon

    Messages:
    201
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Maybe problem is in extension, maybe it parse only jpg files, and not files, that finish jpeg. I had same problem once, and had to modifuy some files.
     
    neds75, Jan 28, 2008 IP
  5. Dan3

    Dan3 Peon

    Messages:
    43
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Yes, it handles all of the image types you mentioned!
     
    Dan3, Jan 28, 2008 IP