Introduced
Php_imagick is a php extension that can be used by PHP to invoke the ImageMagick feature, which enables PHP to have the same functionality as ImageMagick.
ImageMagick is a powerful, stable, and free toolset and development kit that can be used to read, write, and process picture files in more than 185 basic formats, including popular TIFF, JPEG, GIF, PNG, PDF, and PHOTOCD formats. With ImageMagick, you can dynamically generate pictures based on the needs of your Web application, and you can resize, rotate, sharpen, subtractive, or add special effects to one (or a group) of pictures and save the results of the operation in the same format or in other formats.
Php_imagick Program Example
1. Create a thumbnail and display it
<?php
Header (' content-type:image/jpeg ');
$image = new Imagick (' image.jpg ');
If 0 is provided as a width or height parameter,//aspect ratio is maintained
$image->thumbnailimage (0)
echo $image;
? >
2. Create a thumbnail in the directory and save
<?php
$images = new Imagick (Glob (' images/*. JPG '));
foreach ($images as $image) {
//providing 0 forces thumbnailimage to maintain aspect ratio
$image->thumbnailim Age (1024,0);
}
$images->writeimages ();
? >
3. Thumbnail gif animated picture
<?php
/* Create a new Imagick object and read in GIF *
/$im = new Imagick ("Example.gif");
/* Resize all frames/
foreach ($im as $frame) {
/* 50x50 frames
//$frame->thumbnailimage (m);
/* Set the virtual canvas to correct size *
/$frame->setimagepage (0, 0);
} /* Notice writeimages instead of Writeimage
/$im->writeimages ("Example_small.gif", true);
? >
The method of using Php_imagick to realize retro effect
Look at the effect chart first
Retro effect Show
To achieve these effects, we first use Photoshop to implement the following steps.
Open artwork
New layer, with color #c0ffff fill, opacity set to 44%, layer blending mode to soft light
New layer, with color #000699 fill, opacity set to 48%, layer blending mode to exclude
Merging layers
With the PHP code, you just need to follow the steps above to achieve it, the code is as follows:
Open the picture
$im = new Imagick ('./hebe.jpg ');
Create a new layer, using the color ' #C0FFFF ' Fill, the opacity is set to ' 44% '
$layer = new Imagick ();
$layer->newimage ($im->getimagewidth (), $im->getimageheight (), ' #C0FFFF ');
$layer->setimageopacity (0.44);
Overlay to the original artwork, layer blending mode is ' soft light '
$im->compositeimage ($layer, imagick::composite_softlight, 0, 0);
Create a new layer, using the color ' #000699 ' Fill, opacity is set to ' 48% '
$layer = new Imagick ();
$layer->newimage ($im->getimagewidth (), $im->getimageheight (), ' #000699 ');
$layer->setimageopacity (0.48);
Overlay to the original artwork, layer blending mode is ' exclude '
$im->compositeimage ($layer, imagick::composite_exclusion, 0, 0);
Complete!
$im->writeimage ('./vintage.jpg ');
Summarize
The above is the use of Php_imagick to achieve the retro effect of the method, the article introduced by example code or very detailed, interested friends to knock on their own code more convenient to understand, I hope this article on the content of everyone's study or work can bring some help, if you have questions you can communicate message.