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
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts

    combine image upload & image resize scripts

    Uploads an image file from an HTML form:


    PHP Code:
    <?php

    $dir 
    "lists/images/";
    $uploadfile $dir $_FILES["img"]["name"];



    if (
    move_uploaded_file($_FILES["img"]["tmp_name"], $uploadfile)){

    //when chmod-ing, remember $uploadfile includes $dir

    chmod("/home/domain/www/www/path/to/images/$uploadfile"0775);
    echo 
    "markup goes here";
    }

    ?>

    Creates a thumbnail from Original Image:

    PHP Code:
    <?php 

    //resizes (dimensions & filesize) an image to create a thumbnail

    $img $_POST["oSel"]; 
    $src imagecreatefromjpeg($img);  

    // get current image size 

    $width imagesx($src);  
    $height imagesy($src);  

    $aspectRatio 150/$height

    // resize image

    $newWidth abs($width $aspectRatio); 
    $newHeight abs($height $aspectRatio); 

    //create new image

    $newImg imagecreatetruecolor($newWidth,$newHeight);  

    //save new image 

    imagecopyresampled ($newImg,$src,0,0,0,0,$newWidth,$newHeight,$width,$height);  
    imagejpeg($newImg,$img,90);  
    imagedestroy($newImg);
      
    echo 
    "markup goes here";

    ?>

    I'd like to combine the above two scripts. Save one [fullsized] image to one directory, and save a thumbnail of the same image to another directory.

    Any help is appreciated. Thanks!


    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    hey James..

    Have you considered only saving the big image and then generating the thumbnail on the file form the big one? save you space.

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by sir pannels
    hey James..

    Have you considered only saving the big image and then generating the thumbnail on the file form the big one? save you space.

    Hi sir pannels...thanks, for responding.


    Sorry, but I don't get your intended meaning. I don't want to resize the image using height and width attributes, if that's what you mean. I need to also reduce the file size, so I'd prefer to store one [fullsized] image in one directory, and another [thumbsized] image in another directory. I can currently do this with the above scripts, but I'd like to combine the 2 scripts, for a CMS, so that the user doesn't have to select the image twice. Clear as mud???

    Thanks, again.




    -james
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    625
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oops...
    Last edited by jamescover; 10-15-2004 at 12:01 PM.
    "God so loved the world that he gave his only begotten son, so that whosoever believed in him would not perish, but have everlasting life. For God did not send his son into the world to condemn the world, but so that through him the world might be saved. "


  •  

    Posting Permissions

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