php - Image resizing without deformation -


i'm trying create thumbnail gd library, thumbnail distorted. want cut image starting center respecting new resolution , losing old proportion.

what i've tried:

$im = imagecreatefromjpeg($target_file); $n_width = 500; // fix width of thumb nail images $n_height = 500; // fix height of thumb nail imaage $width = imagesx($im); // original picture width stored $height = imagesy($im); // original picture height stored $newimage = imagecreatetruecolor($n_width, $n_height); imagecopyresampled($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height); $thumb_target = $target_dir . $filename_without_ext . '-thumb.' . $params['file_ext']; imagejpeg($newimage, $thumb_target); chmod("$thumb_target", 0777); 

tried change imagecreatetruecolor imagecrop still not behavior want.

please let me know if not clear enough.

solved using imagemanipulator library. found solution in this answer.

my final code:

$im = new imagemanipulator($target_file); $centrex = round($im->getwidth() / 2); $centrey = round($im->getheight() / 2);  $x1 = $centrex - 500; $y1 = $centrey - 500;  $x2 = $centrex + 500; $y2 = $centrey + 500;  $im->crop($x1, $y1, $x2, $y2); $im->save($target_dir . $filename_without_ext . '-thumb.' . $params['file_ext']); 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -