我有一个目前正在使用的PHP脚本,它根据最大宽度和高度创建缩略图.但是,我希望它能够始终创建方形图像并在需要时裁剪图像.
这是我现在使用的:
function makeThumb( $filename, $type ) {
global $max_width, $max_height;
if ( $type == 'jpg' ) {
$src = imagecreatefromjpeg("blocks/img/gallery/" . $filename);
} else if ( $type == 'png' ) {
$src = imagecreatefrompng("blocks/img/gallery/" . $filename);
} else if ( $type == 'gif' ) {
$src = imagecreatefromgif("blocks/img/gallery/" . $filename);
}
if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) {
$newW = $oldW * ($max_width / $oldH);
$newH = $max_height;
} else {
$newW = $max_width;
$newH …Run Code Online (Sandbox Code Playgroud)