ho riscritto un po' tutto perché non riuscivo a comprendere bene il tuo codice
quella che ti propongo è una funzione che mostra a runtime il centro dell'immagine ridimensionata e il codice per usarla
Codice PHP:
<?php
function resizeCropJpeg_Square($source, $dim) {
$filename = $source;
$max = $dim;
list($width, $height) = getimagesize($filename);
$width <= $height ? $c = $max / $width : $c = $max / $height;
$new_width = $c * $width;
$new_height = $c * $height;
$x = 0;
$y = 0;
if($new_width > $new_height) {
$x = ($width - $max * 1/$c) / 2;
}
else {
$y = ($height - $max * 1/$c) / 2;
}
$current_image = imagecreatefromjpeg($filename);
$canvas= imagecreatetruecolor($max, $max);
$image_res = imagecopyresized($canvas, $current_image, 0, 0, $x, $y, $new_width, $new_height, $width, $height);
ob_start();
imagejpeg($canvas, NULL, 100);
$image = ob_get_clean();
imagedestroy($canvas);
return base64_encode($image);
}
$file = "test_P.jpg";
$show_me = resizeCropJpeg_Square($file, 170);
echo '<img src="data:image/jpeg;base64,' . $show_me . '" /><br />IMMAGINE';
?>