PHP.mk документација

Imagick::cropImage

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

imagick.cropimage.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека imagick.cropimage.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
Imagick::cropImage

Референца за `imagick.cropimage.php` со подобрена типографија и навигација.

imagick.cropimage.php

Imagick::cropImage

(PECL imagick 2, PECL imagick 3)

Imagick::cropImageИзвлекува регион од сликата

= NULL

public Imagick::cropImage(
         int $width,
         int $height,
         int $x,
         int $y
): bool

Извлекува регион од сликата.

Параметри

width

The width of the crop

height

The height of the crop

x

The X coordinate of the cropped region's top left corner

y

The Y coordinate of the cropped region's top left corner

Вратени вредности

Патеката до PHP скриптата што треба да се провери. true на успешен исход.

Errors/Exceptions

Фрла ImagickException при грешка.

Примери

Пример #1 Imagick::chopImage()

<?php
function cropImage($imagePath, $startX, $startY, $width, $height) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->cropImage($width, $height, $startX, $startY);
header("Content-Type: image/jpg");
echo
$imagick->getImageBlob();
}

?>

Белешки од корисници 4 белешки

Christian Dehning
пред 15 години
When cropping gif-images (I had no problems with jpg and png images), the canvas is not removed. Please run the following command on the cropped gif, to remove the blank space:

$im->setImagePage(0, 0, 0, 0);
olav на schettler точка net
пред 9 години
Here is a simple function to create a thumbnail. It accepts an additional parameter to set the focus point of the generated thumbnail:

<?php
function thumbnail($image, $new_w, $new_h, $focus = 'center')
{
    $w = $image->getImageWidth();
    $h = $image->getImageHeight();

    if ($w > $h) {
        $resize_w = $w * $new_h / $h;
        $resize_h = $new_h;
    }
    else {
        $resize_w = $new_w;
        $resize_h = $h * $new_w / $w;
    }
    $image->resizeImage($resize_w, $resize_h, Imagick::FILTER_LANCZOS, 0.9);

    switch ($focus) {
        case 'northwest':
            $image->cropImage($new_w, $new_h, 0, 0);
            break;

        case 'center':
            $image->cropImage($new_w, $new_h, ($resize_w - $new_w) / 2, ($resize_h - $new_h) / 2);
            break;

        case 'northeast':
            $image->cropImage($new_w, $new_h, $resize_w - $new_w, 0);
            break;

        case 'southwest':
            $image->cropImage($new_w, $new_h, 0, $resize_h - $new_h);
            break;

        case 'southeast':
            $image->cropImage($new_w, $new_h, $resize_w - $new_w, $resize_h - $new_h);
            break;
    }
}
?>
ElPadre
пред 15 години
Actually, the Imagick::setImagePage(0,0,0,0) is also handy with jpgs and pngs, if you plan to do any more changes on the cropped image that involves positioning and/or gravity (I created a script that does crop, face blur and watermarking in one go, and had a hell of a time determining why the blurs and the watermark text never showed up...).
oxxido at gmail dot com
пред 10 години
I have a function that takes an image, resize and crop it, and save it as normal, then resize it again and crop it again to create the thumbnail. The numbers of the second crop were WAY off, and the calculations were perfect, the problem, was the second crop wasn't resetting the imagePage, so if you try to crop the same image twice, it will be a good idea to reset it first:
<?php
$thumb = new Imagick($file)
$thumb->resizeImage($r_w1,$r_h1,Imagick::FILTER_CATROM,0.9, false);
$thumb->cropImage($w1,$h1,$l1,$t1);
$thumb->writeImage($destinationPath.'/'.$fileName);

$thumb->resizeImage($r_w2,$r_h2,Imagick::FILTER_CATROM,0.9, false);
$thumb->setImagePage(0, 0, 0, 0);
$thumb->cropImage($w2,$h2,$l2,$t2);
$thumb->writeImage($destinationPath.'/'.$fileNameThumb);

?>

BTW, i needed perfect dimentions so i had to set the "bestfit" to false.
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.