Hi, I'm making a script to resize images.
I would like to improve it with two more things:
1. Restrict it to JPG and JPEG images printing a message if the extension is not JPG or JPEG;
2. Print a message if file, new width and new height is left blank.
My code is here:
PHP Code:
<?php // This is the temporary file created by PHP $uploadedfile = $_FILES['uploadfile']['tmp_name']; $newwidth= $_POST['width']; $newheight= $_POST['height'];
//Get File $file = $_FILES['uploadfile'];
// Create an Image from it so we can do the resize $src = imagecreatefromjpeg($uploadedfile);
// Capture the original size of the uploaded image list($width,$height)=getimagesize($uploadedfile);
// This will get the pixels entered by user
$tmp=imagecreatetruecolor($newwidth,$newheight);
// this line actually does the image resizing, copying from the original // image into the $tmp image imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// now write the resized image to disk. I have assumed that you want the // resized, uploaded image file to reside in the ./images subdirectory. $filename = "images/". $_FILES['uploadfile']['name']; imagejpeg($tmp,$filename,100); echo "<center>Resized image to \"$newwidth\"x\"$newheight\"</center>\n"; echo "<center><img src=\"$filename\" border='0'></center>\n"; imagedestroy($src); imagedestroy($tmp); // NOTE: PHP will clean up the temp file it created when the request // has completed. ?>
Could somebody help me please?
|