470,849 Members | 1,116 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

i cannot save resized images

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

Oct 25 '05 #1
1 1540
> 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() ?


Close, it is actually the current working directory. So if this was
done via include it will be in that path. Also what I suggest doing is
checking what the program is doing. My thought is that you have a
notice or warning being generated and that is causing the corruption of
the image, if it is being generated at all.

Try just letting it output to the browser without a header. You should
be able to see more details that way. Also turn your error reporting to
E_ALL via error_reporting(E_ALL); at the beginning of the script.

--
Mike Willbanks
Zend Certified Engineer
http://www.digitalstruct.com
Oct 25 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Dag Eilertsen | last post: by
6 posts views Thread by Christopher Brandsdal | last post: by
1 post views Thread by Hardy Wang | last post: by
1 post views Thread by liuliuliu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.