PDA

View Full Version : what's wrong with my code


sgtmaj
02-10-2004, 05:42 PM
the below section of code runs and says it resized the image but it actually didn't. Can anyone see flaws within the code? Any help will be greatly appreciated. Thanx, Charlie


if ($extension=="gif" or $extension=="jpg" or $extension=="jpeg" or $extension=="jpe" or $extension=="png" or $extension=="swf") { // Picture file
if ($imginfo=@getimagesize($attachment)) {
if (($maxattachwidth>0 and $imginfo[0]>$maxattachwidth) or ($maxattachheight>0 and $imginfo[1]>$maxattachheight)) {

$image_width = $imginfo[0];
$image_height= $imginfo[1];

if ($image_width > $maxattachwidth)
{
$sizefactor = (double) ($maxattachwidth / $image_width);
}
elseif ($image_height > $maxattachheight)
{
$sizefactor = (double) ($maxattachheight / $image_height) ;
}


$newwidth = (int) ($image_width * $sizefactor);
$newheight = (int) ($image_height * $sizefactor);

$newsize = $newwidth . "x" . $newheight;

$cmd = "/usr/local/bin/mogrify -resize $newsize "."$attachment 2>&1";

exec($cmd, $exec_output, $exec_retval);
if($exec_retval > 0)
{
print "ERROR: exec() error: $exec_output[0]";
}
else
{
print "<P align=\"center\">[b]Image was resized from " . $image_width . "x" .
$image_height . " to $newsize</p>";
}

}

sgtmaj
02-12-2004, 10:33 AM
I would have thought that someone would have responded by now. Guess this is more challenging than I figured!!!??!!!

Justin
02-12-2004, 10:59 AM
You were missing two curly braces at the end:


if ($extension=="gif" or $extension=="jpg" or $extension=="jpeg" or $extension=="jpe" or $extension=="png" or $extension=="swf") { // Picture file
if ($imginfo=@getimagesize($attachment)) {
if (($maxattachwidth>0 and $imginfo[0]>$maxattachwidth) or ($maxattachheight>0 and $imginfo[1]>$maxattachheight)) {
$image_width = $imginfo[0];
$image_height= $imginfo[1];
if ($image_width > $maxattachwidth) {
$sizefactor = (double) ($maxattachwidth / $image_width);
}
elseif ($image_height > $maxattachheight) {
$sizefactor = (double) ($maxattachheight / $image_height) ;
}
$newwidth = (int) ($image_width * $sizefactor);
$newheight = (int) ($image_height * $sizefactor);
$newsize = $newwidth . "x" . $newheight;
$cmd = "/usr/bin/mogrify -resize $newsize "."$attachment 2>&1";
exec($cmd, $exec_output, $exec_retval);
if($exec_retval > 0) {
print "ERROR: exec() error: $exec_output[0]";
}
else {
print "<P align=\"center\">[b]Image was resized from " . $image_width . "x" .
$image_height . " to $newsize</p>";
}
}
}
}