|
Posted by google on 10/25/05 02:53
I am missing something elementary I think. I am trying to batch resize
the contents of a directory, using imagecreatefromjpg() etc.
I have tried many scripts and I can only seem to corrupt the jpg. My
latest script is this...
<?php
// The file
$filename = '6.jpg';
// Set a maximum height and width
$width = 10;
$height = 10;
// Content type
header('Content-type: image/jpeg');
//header("Content-Disposition: attachment; filename=6.jpg");
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
if ($width && ($width_orig < $height_orig)) {
$width = ($height / $height_orig) * $width_orig;
} else {
$height = ($width / $width_orig) * $height_orig;
}
// Resample
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height,
$width_orig, $height_orig);
// Output
imagejpeg($image_p, $filename, 100);
?>
I am testing it on a single file, but it destroys the image. Does
imagejpeg write the new file in the current directory ? Or do I need to
do an fputs() ?
Thank you for any comments
Navigation:
[Reply to this message]
|