Use PHP para criar miniaturas. (Cortado ao quadrado)
Eu tenho um script php atualmente estou usando que cria miniaturas com base em uma largura e altura máximas. No entanto, gostaria de sempre criar imagens quadradas e recortá-las quando necessário.
Aqui está o que estou usando agora:
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 = $oldH * ($max_height / $oldW);
}
$new = imagecreatetruecolor($newW, $newH);
imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);
if ( $type == 'jpg' ) {
imagejpeg($new, 'blocks/img/gallery/thumbs/'.$filename);
} else if ( $type == 'png' ) {
imagepng($new, 'blocks/img/gallery/thumbs/'.$filename);
} else if ( $type == 'gif' ) {
imagegif($new, 'blocks/img/gallery/thumbs/'.$filename);
}
imagedestroy($new);
imagedestroy($src);
}
Como eu alteraria isso para realizar o que eu quero (polegares quadrados)?
Desde já, obrigado.