PHP 8.3.4 Released!

Imagick::scaleImage

(PECL imagick 2, PECL imagick 3)

Imagick::scaleImageGörüntünün enboy oranını ayarlar

Açıklama

public Imagick::scaleImage(
    int $genişlik,
    int $yükseklik,
    bool $sığdır = false,
    bool $eski = false
): bool

Görüntünün boyutlarını belirtilen değerlere ayarlar. 0 olarak belirtilen bağımsız değişken görüntünün enboy oranı hesaba katılarak diğer bağımsız değişkene göre hesaplanır.

Bilginize: sığdır bağımsız değişkeninin davranışı Imagick 3.0.0 sürümünde değişmiştir. Evvelce 200x150 ebadındaki bir görüntü 400x400 ebadındaki bir alana sığdırılmak istendiğinde bu yapılmazdı. Artık görüntü 400x300 ebadına getirilerek belirtilen alana sığdırılmaktadır. sığdır bağımsız değişkeni kullanıldığı takdirde yükseklik ve genişliğin ikisi de verilmelidir.

Bağımsız Değişkenler

genişlik

yükseklik

sığdır

Dönen Değerler

Başarı durumunda true döner.

Hatalar/İstisnalar

Hata durumunda bir ImagickException istisnası oluşur.

Sürüm Bilgisi

Sürüm: Açıklama
PECL imagick 2.1.0 Seçimlik sığdır bağımsız değişkeni eklendi. Yöntem artık sadece yükseklik veya genişlik vererek oranlamayı da destekliyor. Hesaplanacak boyut için bağımsız değişkene 0 belirtmek gerekiyor.

Örnekler

Örnek 1 - Imagick::scaleImage() örneği

<?php
function scaleImage($imagePath) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->scaleImage(150, 150, true);
header("Content-Type: image/jpg");
echo
$imagick->getImageBlob();
}

?>

add a note

User Contributed Notes 6 notes

up
28
benford at bluhelix dot com
14 years ago
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.
up
9
vincent dot hoen at gmail dot com
16 years ago
Here is an easy way to resize an animated gif :

$picture = new Imagick('animated_gif.gif');

foreach($picture as $frame){
$frame->scaleImage($width, $height);
}
up
7
octave at web dot de
14 years ago
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
?>
up
3
agamemnus at flyingsoft dot pw
10 years ago
Warning: this will blur your edges in possibly unexpected ways. For better control, use resizeImage, instead.
up
5
clickconvert at gmail dot com
11 years ago
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();
?>
up
-6
peter at icb dot at
14 years ago
If using the fit-parameter this function sometimes seems not to work when one of the two sizes (width or height) is the same size as the image has. For example:

<?php
$image
= new Imagick('800x480.jpg');
$image->scaleImage(640, 480, true);

// $image is still 800x480
?>

You have to calculate the new sizes yourself and use false for $fit in this case.
To Top