This program is supposed to proportionally resize an image so that the longest side is 700px. Most of it seems to work, but I can’t seem to get it to actually make the new picture. I think whatever problems there are lie after the “defines old_img” comment.
[php]
<?php $image = "7.JPG"; $sizearray = getimagesize($image); $width = $sizearray[0]; $height = $sizearray[1]; echo "Dimensions: $width x $height"; # Give $new_width and $new_height values if ($width > $height) { $height2 = ($height * 700)/$width; $new_height = round($height2, 0, PHP_ROUND_HALF_UP); $new_width = 700; echo "Width greater than height"; } elseif ($width < $height) { $width2 = ($width * 700)/$height; $new_width = round($width2, 0, PHP_ROUND_HALF_UP); $new_height = 700; echo "
Width less than height"; } elseif ($width == $height) { $new_height = 700; $new_width = 700; echo "width equals height"; } else{ echo "No resizing needed"; } # Deals with extension differences $tmp = split("\.", basename($image)); $ext = $tmp[1]; $old_img = ""; echo "
The image's extension is {$ext}."; if($ext == "jpg"|$ext =="JPG"|$ext == "jpeg"|$ext == "JPEG") { $old_img = imagecreatefromjpeg($image); } elseif($ext == "PNG"|$ext == "png") { $old_img = imagecreatefrompng($image); } #defines old_img $new_img = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($new_img, $old_img, 0, 0, 0, 0, $new_width, $new_height, $width, $height); if($ext == "jpg"|$ext =="JPG"|$ext == "jpeg"|$ext == "JPEG") #error here? { imagejpeg($new_image, "newpic.{$ext}", 70); } elseif($ext == "PNG"|$ext == "png") { imagepng($new_image, "newpic.{$ext}", 2); } ?>
[/php]