You are here: i cannot save resized images « PHP Programming Language « IT news, forums, messages
i cannot save resized images

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация