Jump to content

[SOLVED] Image resizing help


s4salman

Recommended Posts

Dear i am using the script attcahed, i have some photos in 1600x1200 size. When i craete thumbnails using this script, it uploads 1600x1200 size image on the server. Also it craetes 1024x768 and 800x600 size dynamically.

But i also want to create 640x480 pixel image.

 

How can i do this.What additional code in need to put in it.

 

Please help

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/144189-solved-image-resizing-help/
Share on other sites

Landavia, i did not got your point.

<?php
        if(isset($_POST['submit'])){
          if (isset ($_FILES['new_image'])){
              $imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
              $target = "images/".$imagename;
              move_uploaded_file($source, $target);
              
              $imagepath = $imagename;
              $save = "images/" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file

              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 1024; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 

              $save = "images/sml_" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file

              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 800; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 





            
        
          }
        }
?><form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
        <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
        <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
</form>
<?php
if(isset($_POST['submit'])){
echo "Large image: <img src='images/".$imagepath."'><br>"; 
            echo "Thumbnail: <img src='images/sml_".$imagepath."'>"; 
}
?>

about the script

u combine all form and resize script on 1 file.. well that's nice

but good..

 

btw.. u ask

>>What additional code in need to put in it.

u already built it.. u just change the value into 640 like below

 

list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 640; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 

Dear when i added this code :

 

list($width, $height) = getimagesize($file) ;
                                                         
              $modwidth = 640;
                                                         
              $diff = $width / $modwidth;
                                                       
              $modheight = $height / $diff;
              $tn = imagecreatetruecolor($modwidth, $modheight) ;
              $image = imagecreatefromjpeg($file) ;
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
                                                       
              imagejpeg($tn, $save, 100) ; [code]

it is now only generating 640x480 size image.and original file is uploading. it is not generating 800x600 size image.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.