продолжения к этому вопросу: How to get new width and height after an image has been rotated with imagerotate()?Получите ширину и высоту уменьшенного изображения после изображения?
Ответ, который я получил на основе фактического размера изображений имен файлов, но если я хочу начать с другой шириной и высоты.
Как я могу это достичь? Ниже код для моей попытки ...
$ps['product_angle'] = 77; //Could be any angle
$filename = 'test.png' //filename to the original product
list($source_width, $source_height) = getimagesize($filename);
$source_image = imagecreatefromjpeg($filename);
//Example for clarification (this is parameters that is used to save new image)
$ps['product_width'] = 40; //for example $source_width = 200
$ps['product_height'] = 80; //and $source_height = 400
$angle = $ps['product_angle'];
if (intval($angle) <> 0) {
//Actual dimensions of image from filename
$current_source_x = imagesx($source_image);
$current_source_y = imagesy($source_image);
//Get current ratio of "scaled down image"
$ratio_x = $ps['product_width']/$current_source_x;
$ratio_y = $ps['product_height']/$current_source_y;
$source_image = imagerotate(
$source_image,
360-$angle,
imageColorAllocateAlpha($source_image, 255, 255, 255, 127)
);
//New dimensions from actual filename
//This would be fine if I just wanted the new width and height
//based on the filenames dimension, but I want new dimensions
//for the "scaled downed version" of the image (40, 80)
$new_image_source_x = imagesx($source_image);
$new_image_source_y = imagesy($source_image);
//I tried this, but obviously I'm doing something totally wrong
$new_width = ($new_image_source_x - $current_source_x) * $ratio_x;
$new_height = ($new_image_source_y - $current_source_y) * $ratio_y;
//Set new width after rotation
$ps['product_width'] = $new_width;
$ps['product_height'] = $new_height;
}
$ps['source_image'] = $source_image;
list($source_width, $source_height) = getimagesize($filename);
$dest_width = (int)$ps['product_width'];
$dest_height = (int)$ps['product_height'];
//Resize source-image to new width and height
//
imagecopyresized($dest_image, $ps['source_image'], 0, 0, 0, 0, $dest_width, $dest_height, $source_width, $source_height);
Возможно, я что-то очень существенное ....
UPDATE
Пример реальных значений отсутствует ...
image current width63.224619257754
image current height80.210337864315
//after calculation
image new width37.583523669887
image newt height21.716336015666
where angle is 41.10419020401479
Пожалуйста, добавьте детали на свой вопрос: Какая ошибка, какие значения у вас есть? – Daniel
Я обновил свой вопрос, потому что у меня были некоторые ошибки копирования и вставки, но кроме того - я не получаю ожидаемой ширины и высоты ($ new_width и $ new_height). – bestprogrammerintheworld
Новая ширина и высота становятся очень маленькими. Посмотрите на обновление – bestprogrammerintheworld