Ben fotoğraf yükleme ve 300x200 piksel onları yeniden boyutlandırma am
Ben imagick uzantısı ve özellikle adaptiveResizeImage () fonksiyonunu kullanıyorum.
Görüntünün tarafta boşluklarla bir sürü (dikey veya yatay bağlı) olduğunu bestfit kullanırken yükledi.
Ya ben yaptım diye tüm alanı (hiçbir boşluk) doldurup daha uzundu (yükseklik veya genişlik) kırpmak, yani ben daha çok boşluk var daha bir imaj kaybederiz yeniden boyutlandırmak oldu.
imagick uzantısı ile bunu yapmak için kolay bir yolu var mı?
EDIT: Ben ne gerekli yapmayı başardı, ama daha iyi bir yolu olmalı vardır
header('Content-type: image/jpeg');
// target sizes
$target_width = 300 ;
$target_height = 100 ;
// create new image
$image = new Imagick('test.jpg');
// get current size and calculate diffences from target sizes
$size = $image->getImageGeometry();
$size['width_diff'] = $target_width/$size['width'] ;
$size['height_diff'] = $target_height/$size['height'] ;
// resize by smallest size
if($size['width_diff']>=$size['height_diff'])
{
$width = $target_width ;
$height = $size['height']*$size['width_diff'] ;
}
else
{
$width = $size['width']*$size['height_diff'] ;
$height = $target_height ;
}
// get offsets
$x = ($width-$target_width)/2 ;
$y = ($height-$target_height)/2 ;
// resize and offset image
$image->adaptiveResizeImage($width, $height) ;
$image->extentImage($target_width, $target_height,-$x,-$y);
// output and clean up
echo $image ;
$image->clear();
$image->destroy();