C++ :
int overflow(int n)
{
return overflow(1);
}
Если вы пытаетесь создать эскизы, вы должны сначала изменить размер изображения с помощью imagecopyresampled ();
. Вы должны изменить размер изображения так, чтобы размер меньшей стороны изображения был равен соответствующей стороне большого пальца.
Например, если ваше исходное изображение имеет размер 1280x800 пикселей, а размер вашего большого пальца - 200x150 пикселей, вы должны изменить размер изображения на 240x150px, а затем обрежьте его до 200x150px. Это сделано для того, чтобы соотношение сторон изображения не изменилось.
Вот общая формула для создания эскизов:
$image = imagecreatefromjpeg($_GET['src']);
$filename = 'images/cropped_whatever.jpg';
$thumb_width = 200;
$thumb_height = 150;
$width = imagesx($image);
$height = imagesy($image);
$original_aspect = $width / $height;
$thumb_aspect = $thumb_width / $thumb_height;
if ( $original_aspect >= $thumb_aspect )
{
// If image is wider than thumbnail (in aspect ratio sense)
$new_height = $thumb_height;
$new_width = $width / ($height / $thumb_height);
}
else
{
// If the thumbnail is wider than the image
$new_width = $thumb_width;
$new_height = $height / ($width / $thumb_width);
}
$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );
// Resize and crop
imagecopyresampled($thumb,
$image,
0 - ($new_width - $thumb_width) / 2, // Center the image horizontally
0 - ($new_height - $thumb_height) / 2, // Center the image vertically
0, 0,
$new_width, $new_height,
$width, $height);
imagejpeg($thumb, $filename, 80);
Не тестировал, но он должен работать.
EDIT
Теперь протестировано и работает.