Imagick::distortImage

(No version information available, might be only in CVS)

Imagick::distortImage — Distorts an image using various distortion methods

Описание

bool Imagick::distortImage ( int $method , array $arguments , bool $bestfit )

Distorts an image using various distortion methods, by mapping color lookups of the source image to a new destination image usally of the same size as the source image, unless 'bestfit' is set to TRUE.

If 'bestfit' is enabled, and distortion allows it, the destination image is adjusted to ensure the whole source 'image' will just fit within the final destination image, which will be sized and offset accordingly. Also in many cases the virtual offset of the source image will be taken into account in the mapping.

This functionality is present if Imagick is compiled against ImageMagick 6.3.6 or later.

Список параметров

method

The method of image distortion. See distortion constants

arguments

The arguments for this distortion method

bestfit

Attempt to resize destination to fit distorted source

Возвращаемые значения

Returns TRUE on success.

Errors/Exceptions

Throws ImagickException on error.

Примеры

Пример #1 Using Imagick::distortImage():

Distort an image and write it to the disk.

<?php

$im 
= new imagick"example.jpg" );

$im->distortImageImagick::DISTORTION_PERSPECTIVE, array( 7,404,304,1244,12385,122100,12385,2100,30 ), true );

$im->writeImage"example_out.jpg" );

?>

Коментарии

Slide image with shadow using distortImage

<?php

$slideValue 
150;

// Create new object 
$im = new Imagick("grnhrs.jpg");

// Resize 
$im->thumbnailImage(500,400);

// Set the image format to png 
$im->setImageFormat('png');

//Clone the current object
$shadow $im->clone();

//Set image background color to black (this is the color of the shadow)
$shadow->setImageBackgroundColor( new ImagickPixel'black' ) );
 
 
//Create the shadow 
$shadow->shadowImage80105);

// Fill background area with transparent for image
//VIRTUALPIXELMETHOD_TRANSPARENT
$im->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_ TRANSPARENT);

// Activate matte 
$im->setImageMatte(true);

//Control points for the distortion 
$controlPoints = array( 00,
                       
$slideValue0,
                       
                       
0$im->getImageHeight(),
                       
0$im->getImageHeight(),
                       
                       
$im->getImageWidth(), 0,
                       
$im->getImageWidth(), 0,
                       
                       
$im->getImageWidth(), $im->getImageHeight(),
                       
$im->getImageWidth()-$slideValue$im->getImageHeight());
                       
// Perform the distortion 
$im->distortImage(Imagick::DISTORTION_PERSPECTIVEPROJECTION$controlPointstrue);

// Perform the distortion in shadow image
$shadow->distortImage(Imagick::DISTORTION_PERSPECTIVEPROJECTION$controlPointstrue);

// Imagick::shadowImage only creates the shadow.
// That is why the original image is composited over it 
$shadow->compositeImage$imImagick::COMPOSITE_OVER0);

/* Ouput the image */
header("Content-Type: image/png");
echo 
$shadow;

?>
2011-02-04 12:13:33
http://php5.kiev.ua/manual/ru/function.imagick-distortimage.html
Автор:
Affine

<?php 
$image 
= new imagick"opossum.jpg" ); 
$points = array( 
               
0,025,25,   
               
100,0100,50 
               
);
$image->setimagebackgroundcolor("#fad888");
$image->setImageVirtualPixelMethodimagick::VIRTUALPIXELMETHOD_BACKGROUND );
$image->distortImageImagick::DISTORTION_AFFINE$pointsTRUE ); 
header"Content-Type: image/jpeg" ); 
echo 
$image;
?>

Affine Projection

<?php 
$image 
= new imagick"opossum.jpg" ); 
$points = array( 0.9,0.3,
                -
0.2,0.7,
                 
20,15 );
$image->setimagebackgroundcolor("#fad888");
$image->setImageVirtualPixelMethodimagick::VIRTUALPIXELMETHOD_BACKGROUND );
$image->distortImageImagick::DISTORTION_AFFINEPROJECTION$pointsTRUE ); 
header"Content-Type: image/jpeg" ); 
echo 
$image;
?>

Arc

<?php 
$image 
= new imagick"opossum.jpg" ); 
$draw = new imagickdraw(); 
$degrees = array( 180 );
$image->setimagebackgroundcolor("#fad888");
$image->setImageVirtualPixelMethodimagick::VIRTUALPIXELMETHOD_BACKGROUND );
$image->distortImageImagick::DISTORTION_ARC$degreesTRUE ); 
header"Content-Type: image/jpeg" ); 
echo 
$image;
?>

Rotated Arc

<?php 
$image 
= new imagick"opossum.jpg" ); 
$draw = new imagickdraw(); 
$degrees = array( 1804510020 );
$image->setimagebackgroundcolor("#fad888");
$image->setImageVirtualPixelMethodimagick::VIRTUALPIXELMETHOD_BACKGROUND );
$image->distortImageImagick::DISTORTION_ARC$degreesTRUE ); 
header"Content-Type: image/jpeg" ); 
echo 
$image;
?>

Bilinear

<?php 
$image 
= new imagick"opossum.jpg" ); 
$points = array( 
               
0,025,25# top left 
               
176,0126,0# top right
               
0,1350,105# bottom right 
               
176,135176,135 # bottum left
               
);
$image->setimagebackgroundcolor("#fad888");
$image->setImageVirtualPixelMethodimagick::VIRTUALPIXELMETHOD_BACKGROUND );
$image->distortImageImagick::DISTORTION_BILINEAR$pointsTRUE ); 
header"Content-Type: image/jpeg" ); 
echo 
$image;
?>

Perspective

<?php 
$image 
= new imagick"opossum.jpg" ); 
$points = array( 
               
0,025,25# top left 
               
176,0126,0# top right
               
0,1350,105# bottom right 
               
176,135176,135 # bottum left
               
);
$image->setimagebackgroundcolor("#fad888");
$image->setImageVirtualPixelMethodimagick::VIRTUALPIXELMETHOD_BACKGROUND );
$image->distortImageImagick::DISTORTION_PERSPECTIVE$pointsTRUE ); 
header"Content-Type: image/jpeg" ); 
echo 
$image;
?>

Scale Rotate Translate

<?php 
$image 
= new imagick"opossum.jpg" ); 
$points = array( 
                 
1.5# scale 150%
                 
150 # rotate
               
);
$image->setimagebackgroundcolor("#fad888");
$image->setImageVirtualPixelMethodimagick::VIRTUALPIXELMETHOD_BACKGROUND );
$image->distortImageimagick::DISTORTION_SCALEROTATETRANSLATE$pointsTRUE ); 
header"Content-Type: image/jpeg" ); 
echo 
$image;
?>
2011-04-12 09:11:07
http://php5.kiev.ua/manual/ru/function.imagick-distortimage.html

    Поддержать сайт на родительском проекте КГБ