Resizing
|
|
|
|
Two files are needed: sampleform.php3 and image.php3
You need to have jpgtn installed. In these samplescripts jpgtn is assumed to be in the same directory as the scripts.
jpgtn can be found at: http://sunsite.anu.edu.au/archives/linux/metalab/apps/graphics/misc/
To use jpgtn in these scripts, the configurationfile of jpgtn must be modified before compiling:
In jpgtn.h change the parameter MAXSIZE (line 7) like this:
#define MAXSIZE 640 /* But can be as big as you'd like */
Then do:
make
copy jpgtn to your sampledirectory
file: image.php3
<?
header ("Content-type: image/jpeg");
if (isset ($img) and file_exists($img))
passthru ("./jpgtn -s $size -q $qual -S $img"); ?>
file: sampleform.php3
<?
$svrimg="sample.jpg"; /* Change this to a filename that suits your needs */ $defaultsize=640; /* Store images as 640 pixels max (width or height) */ $defaultqual=80; /* Store images with quality 80 */
if ($save && $pcimg && file_exists($pcimg)){
if(file_exists($svrimg))
unlink($svrimg);
exec("./jpgtn -s $defaultsize -q $defaultqual -S $pcimg > ".$svrimg);
unlink ($pcimg);
} ?> <html>
<head>
<title>Sample script for resizing images</title>
</head>
<body>
<? if (file_exists($svrimg)){?>
<img src="image.php3?img=<?echo $svrimg;?>&qual=50&size=300" border=0>
<?}else echo "No image uploaded yet";?>
<form name="uploadform" enctype="multipart/form-data" method="post">
<table>
<tr>
<td>
Select an image file (JPEG)
</td>
<td>
<input type="file" name="pcimg">
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="save" value="Upload image">
</td>
</tr>
</table>
</form>
</body>
</html>
|
|
|
Usage Example
|
|
|
Rate This Script
|
|
|
|