SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    New York
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why does this not resize my photo uploads?

    From an upload script, it moves the file to the appropriate directory and then resizes. The upload and moving is fine, but the script just does not resize it. I want it to make a jpeg file regardless of the file type uploaded.
    PHP Code:
    function resize($width$height$quality$filename) {
            
    // please fill out this form...
            
    list($srcw$srch$srct$srca) = getimagesize($filename);
            
    // strip extensions
            
    $newFileName preg_replace('/\.[gifjpn]{3}$/'''$filename1);
            switch(
    $srct)
            {
                
    // gif format
                
    case 1:
                
    $image = @imagecreatefromgif($filename);
                break;

                
    // jpg format
                
    case 2:
                
    $image = @imagecreatefromjpeg($filename);
                break;

                
    // png format
                
    case 3:
                
    $image = @imagecreatefrompng($filename);
                break;
            }
            
    $newImage imagecreatetruecolor($width$height);
            
    imagecopyresampled($newImage$image0000$width$height$srcw$srch);
            return 
    imagejpeg($newImage$filename$quality);
            
    imagedestroy($image);
            
    imagedestroy($newImage);
        } 
    This is my first time working with image resizing. Any ideas why this might not be working as it should? BTW, this follows SitePoint's article on building a photo gallery script.

  2. #2
    Non-Member St.'s Avatar
    Join Date
    Nov 2004
    Location
    Cloud #9
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    script looks like good

    maybe $width = $srcw and $height = $srch ?

    and why you save resized image into $filename? maybe try saving into other file?

  3. #3
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    New York
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to replace the file. The original files are moved with chmod 0777.

    I can echo all the $srcx variables. However lines like:
    echo imagejpeg();
    I do not get anything echoed out.

  4. #4
    Non-Member St.'s Avatar
    Join Date
    Nov 2004
    Location
    Cloud #9
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's stupid, but maybe browser caches your image? Did you check it?

  5. #5
    SitePoint Addict
    Join Date
    Jan 2004
    Location
    New York
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No. I check the files via ftp and they're all the same size.

  6. #6
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    2 things I can see

    • your calls to imagedestroy will never be called because of the return ... statement
    • you create $newFileName but you never use it


    Hope this helps


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
  •