Image Resample
| From: | Jonathan Duncan | Date: | Tue, 08 Apr 2003 22:42:30 +0000 |
| Subject: | Image Resample | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-142970@lists.php.net to get a copy of this message | ||
I am trying to upload a file and then resample it to a smaller size. Using
the script below the file gets copied to the server but then it gives me
this error message:
Warning: Supplied argument is not a valid Image resource in
/path/to/file/do_upload.php on line 8
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
<HTML>
<HEAD>
<TITLE>Upload a File</TITLE>
</HEAD>
<BODY>
<FORM METHOD="post" ACTION="do_upload.php"
ENCTYPE="multipart/form-data">
<P><B>File to Upload:</B><BR>
<INPUT TYPE="File" NAME="img1" SIZE="30"></P>
<INPUT TYPE="Submit" NAME="submit" VALUE="Upload
File"></P>
</FORM>
</BODY>
</HTML>
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
<?
if ($img1_name != "") {
if ($img1_size <= 100000) {
copy("$img1", "pics/$img1_name") or die("Couldn't copy the
file.");
$src_img = "pics/$img1_name";
$dst_img = "pics/image_resampled.jpg";
$imageinfo = getimagesize("pics/".$img1_name);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, 10, 10,
$imageinfo[0], $imageinfo[1]);
} else {
echo "The file you are trying to upload ($img1_name) is larger
($img1_size) than 1kb.";
}
} else {
die("No input file specified");
}
?>
<HTML>
<HEAD>
<TITLE>File Upload</TITLE>
</HEAD>
<BODY>
<P>You sent: <? echo $img1_name; ?>, a <?echo $img1_size; ?>
byte file with a mime type of <? echo $img1_type; ?>.</P>
<br><br>
<img src="<? echo "pics/".$img1_name; ?>"><br><br>
<img src="pics/image_resampled.jpg">
</BODY>
</HTML>
*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Thanks,
Jonathan Duncan