image_scale
includes/image.inc, строка 115
- Версии
- 5 – 6
image_scale($source, $destination, $width, $height)
Scales an image to the given width and height while maintaining aspect ratio.
Параметры
$source
The filepath of the source image
$destination
The file path of the destination image
$width
The target width
$height
The target height
Возвращаемое значение
True or FALSE
, based on success
Код
<?php
function image_scale($source, $destination, $width, $height) {
$info = image_get_info($source);
// don't scale up
if ($width >= $info['width'] && $height >= $info['height']) {
return FALSE;
}
$aspect = $info['height'] / $info['width'];
if ($aspect < $height / $width) {
$width = (int)min($width, $info['width']);
$height = (int)round($width * $aspect);
}
else {
$height = (int)min($height, $info['height']);
$width = (int)round($height / $aspect);
}
return image_toolkit_invoke('resize', array($source, $destination, $width, $height));
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии