I have writted the following code to resize images:
<?php
// The file
$file_dir = "/xxxx/xxxx/xxxx/xxxx";
$filename = "$file_dir/$id/$albumName/$filename_name";
// make sure filename is set
print "<p class=text>the filename is: $filename</p>";
// Set a maximum height and width
$width = 600;
$height = 600;
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
// make sure original dimentions are set
print "<p class=text>width_orig is: $width_orig</p>";
print "<p class=text>height_orig is: $height_orig</p>";
$ratio_orig = $width_orig/$height_orig;
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
// make sure new dimentions are set
print "<p class=text>width is: $width</p>";
print "<p class=text>height is: $height</p>";
// Load
$thumb = imagecreatetruecolor($width, $height);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height);
// Output
imagejpeg($thumb, $file_dir/$id/$albumName/$filename, 100);
?>
But I get the following error:
Warning: imagecopyresized(): Invalid image dimensions
Any help on what's wrong would be most appreciated.
Thanks,
Rupert