470,810 Members | 886 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

Image Resize script in php

57
Sir
i want to resize image. Following script working in my local server. But This coding doesn't work in php 2.6.0. please help me
Expand|Select|Wrap|Line Numbers
  1. <form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
  2.         <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
  3.         <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button>
  4. </form>
  5. <?php
  6.         if(isset($_POST['submit'])){
  7.           if (isset ($_FILES["new_image"])){
  8.               $imagename = $_FILES["new_image"]["name"];
  9.               $source = $_FILES["new_image"]["tmp_name"];
  10.               $target = "images/".$imagename;
  11.               //$prefix = 'small_';
  12.               move_uploaded_file($source, $target);
  13.  
  14.               $imagepath = $imagename;
  15.               $save = "images/sml_" . $imagepath; //This is the new file you saving
  16.               $file = "images/" . $imagepath; //This is the original file
  17.  
  18.               list($width, $height) = getimagesize($file) ; 
  19.  
  20.               $modwidth = 150; 
  21.  
  22.               $diff = $width / $modwidth;
  23.  
  24.               $modheight = $height / $diff; 
  25.               $tn = imagecreatetruecolor($modwidth, $modheight) ; 
  26.               $image = imagecreatefromjpeg($file) ; 
  27.               imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
  28.  
  29.               imagejpeg($tn, $save, 100) ; 
  30.  
  31.               $save = "images/sml_" . $imagepath; //This is the new file you saving
  32.               $file = "images/" . $imagepath; //This is the original file
  33.  
  34.               list($width, $height) = getimagesize($file) ; 
  35.  
  36.               $modwidth = 80; 
  37.  
  38.               $diff = $width / $modwidth;
  39.  
  40.               $modheight = $height / $diff; 
  41.               $tn = imagecreatetruecolor($modwidth, $modheight) ; 
  42.               $image = imagecreatefromjpeg($file) ; 
  43.               imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
  44.  
  45.               imagejpeg($tn, $save, 100) ; 
  46.             echo "Large image: <img src='images/".$imagepath."'><br>"; 
  47.             echo "Thumbnail: <img src='images/sml_".$imagepath."'>"; 
  48.  
  49.           }
  50.         }
  51. ?>
  52.  
Jun 2 '08 #1
3 2875
Noorain
57
Sir
i want to resize image. Following script working in my local server. But This coding doesn't work in php 2.6.0. please help me

<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'])){
if (isset ($_FILES["new_image"])){
$imagename = $_FILES["new_image"]["name"];
$source = $_FILES["new_image"]["tmp_name"];
$target = "images/".$imagename;
//$prefix = 'small_';
move_uploaded_file($source, $target);

$imagepath = $imagename;
$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 = 150;

$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 = 80;

$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) ;
echo "Large image: <img src='images/".$imagepath."'><br>";
echo "Thumbnail: <img src='images/sml_".$imagepath."'>";

}
}
?>

Sir
This coding doesn't work in PHP Version 5.1.6 please help me......................
thanks
Jun 2 '08 #2
hsriat
1,654 Expert 1GB
The code as such works for me.

It seems like GD is not working on you server.
(link)
Jun 2 '08 #3
Atli
5,058 Expert 4TB
Sir
This coding doesn't work in PHP Version 5.1.6 please help me......................
thanks
Hi.
Simply telling us that it doesn't work is of no use to us.

How is it supposed to be working?
How is it really working?
Are you getting any errors?

Have you tried to fix this yourself?
What did you do? Did it change anything?

Having said that, I would have to agree with Harpreet.
When a working code that is dealing with image manipulation fails on a new server, the GD extension is most likely just missing.

P.S.
Use [code] tags when posting code examples.
See the Posting Guidelines for more info on that.
Jun 2 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Chris Dewin | last post: by
1 post views Thread by Ulf Schleth | last post: by
10 posts views Thread by David W. Simmonds | last post: by
reply views Thread by Mattia | last post: by
3 posts views Thread by kayahr | last post: by
8 posts views Thread by infoseekar | last post: by
anfetienne
14 posts views Thread by anfetienne | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.