If anyone finds "The other parameter will be calculated if 0 is passed as either param. " to be a bit confusing, it means approximately this:
<?php
$im = new Imagick('example.jpg');
$im->scaleImage(300, 0);
?>
This scales the image such that it is now 300 pixels wide, and automatically calculates the height to keep the image at the same aspect ratio.
<?php
$im = new Imagick('example.jpg');
$im->scaleImage(0, 300);
?>
Similarly, this example scales the image to make it 300 pixels tall, and the method automatically recalculates the image's height to maintain the aspect ratio.Imagick::scaleImage
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Imagick::scaleImage
Референца за `imagick.scaleimage.php` со подобрена типографија и навигација.
Imagick::scaleImage
(PECL imagick 2, PECL imagick 3)
Imagick::scaleImage — Ја менува големината на сликата
= NULL
int
$columns,int
$rows,bool
$bestfit = false,bool
$legacy = false): bool
Ја менува големината на сликата на дадените димензии. Другиот параметар ќе биде пресметан ако се помине 0 како кој било од параметрите.
Забелешка: Однесувањето на параметарот
bestfitсе промени во Imagick 3.0.0. Пред оваа верзија, дадени димензии 400x400, слика со димензии 200x150 би останала недопрена. Во Imagick 3.0.0 и подоцна, сликата би била зголемена до големина 400x300 бидејќи ова е „најдоброто вклопување“ за дадените димензии. Акоbestfitпараметарот се користи, мора да се дадат и ширина и висина.
Параметри
columns-
rows-
bestfit-
Вратени вредности
Патеката до PHP скриптата што треба да се провери. true на успешен исход.
Errors/Exceptions
Фрла ImagickException при грешка.
Дневник на промени
| Верзија | = NULL |
|---|---|
| PECL imagick 2.1.0 | Додаден е опционален параметар за вклопување. Овој метод сега поддржува пропорционално скалирање. Поминете нула како кој било од параметрите за пропорционално скалирање. |
Примери
Пример #1 Imagick::minifyImage()
<?php
function scaleImage($imagePath) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->scaleImage(150, 150, true);
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();
}
?>Белешки од корисници 5 белешки
Here is an easy way to resize an animated gif :
$picture = new Imagick('animated_gif.gif');
foreach($picture as $frame){
$frame->scaleImage($width, $height);
}When using the "fit = true" option, the image will only scale down, but never scale up:
<?php
$im = new Imagick('1600x1200.jpg');
$im->scaleImage(2000, 1500, true); // => 1600x1200
$im->scaleImage(1000, 500, true); // => 666x500
?>Need to resize portrait and landscape images (and convert to 72ppi)? These will fit an area of 800x600 without distorting, no matter how tall or wide.
<?php
$img = new Imagick($img_loc.$file);
$img->setImageResolution(72,72);
$img->resampleImage(72,72,imagick::FILTER_UNDEFINED,1);
$img->scaleImage(800,0);
$d = $img->getImageGeometry();
$h = $d['height'];
if($h > 600) {
$img->scaleImage(0,600);
$img->writeImage($resized_loc.$file);
} else {
$img->writeImage($resized_loc.$file);
}
$img->destroy();
?>Warning: this will blur your edges in possibly unexpected ways. For better control, use resizeImage, instead.