$sh * $maxw) { //width must fit $dw = $maxw; $dh = $dw * $sh / $sw; } else { //height must fit $dh = $maxh; $dw = $dh * $sw / $sh; } } break; case 'distort': $dw = $maxw; $dh = $maxh; break; case 'square': if ($sw > $sh) { //landscape $dw = $dh = $maxh; $sx = ($sw - $sh) / 2; $sy = 0; $sw = $sh; } else { //portrait $dh = $dw = $maxw; $sx = 0; $sy = ($sh - $sw) /2; $sh = $sw; } break; default: trigger_error("UNKNOWN IMAGE RESIZE STYLE [$imgstyle]"); break; } $im2 = imagecreatetruecolor($dw, $dh); if ($imgstyle == 'square') { imagecopyresampled($im2, $im, 0, 0, $sx, $sy, $dw, $dh, $sw, $sh); } else { imagecopyresampled($im2, $im, 0, 0, 0, 0, $dw, $dh, $sw, $sh); } ob_start(); imagejpeg($im2, '', param('image resize quality')); imagedestroy($im2); $imagedata = ob_get_contents(); ob_end_clean(); imagedestroy($im); } else { trigger_error('RESIZE IMAGE RECEIVED A NON-IMAGE PARAMETER'); } return $imagedata; } function rotate_image($imagedata, $times) { $times = $times % 4; $im = @imagecreatefromstring($imagedata); if ($im) { //if image is really an image $im2 = imagerotate($im, 90 * $times, 0); ob_start(); imagejpeg($im2, '', param('image resize quality')); imagedestroy($im2); $imagedata = ob_get_contents(); ob_end_clean(); imagedestroy($im); } else { trigger_error('ROTATE IMAGE RECEIVED A NON-IMAGE PARAMETER'); } return $imagedata; } ?>