Use php_imagick to achieve retro effect, php_imagick retro
Introduction
Php_imagick is a PHP extension that allows PHP to call the ImageMagick function. Using this extension can make PHP have the same functions as ImageMagick.
ImageMagick is a powerful, stable, and free toolkit that can be used to read, write, and process image files in over 185 basic formats, including popular TIFF, JPEG, GIF, PNG, PDF, and PhotoCD. By using ImageMagick, You can dynamically generate images based on the needs of web applications. You can also resize, rotate, sharpen, subtract, or add special effects to one or more images, save the operation results in the same format or other formats.
Php_imagick program example
1. Create a thumbnail and display it
<?phpheader('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(100, 0);echo $image;?>
2. Create a thumbnail under the Directory and save it
<?php$images = new Imagick(glob('images/*.JPG'));foreach($images as $image) {// Providing 0 forces thumbnailImage to maintain aspect ratio$image->thumbnailImage(1024,0);}$images->writeImages();?>
3. scale down GIF animated images
<?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(50, 50);/* Set the virtual canvas to correct size */$frame->setImagePage(50, 50, 0, 0);}/* Notice writeImages instead of writeImage */$im->writeImages("example_small.gif", true);?>
How to Use php_imagick to achieve retro Effect
Let's take a look.
Retro effect display
To achieve the above effect, we first use Photoshop to implement it using the following steps.
Open source Image
Create a new layer and fill it with color # C0FFFF. The Opacity is set to 44%, and the blending mode of the layer is soft.
Create a new layer and fill it with color #000699. The Opacity is set to 48%, and the blending mode of the layer is excluded.
Merge Layers
With PHP code, you only need to follow the above steps to implement it. The Code is as follows:
// Open the image $ im = new Imagick ('. /hebe.jpg '); // create a layer. Fill in the color' # c0ffff' and set the opacity to '000000' $ layer = new Imagick (); $ layer-> newImage ($ im-> getImageWidth (), $ im-> getImageHeight (), '# c0ffff'); $ layer-> setImageOpacity (0.44 ); // overlay the image to the source image. The mixed layer mode is 'softening out' $ im-> compositeImage ($ layer, Imagick: COMPOSITE_SOFTLIGHT, 0, 0). // create a layer, after the color is filled with '#000699', the opacity is set to '000000' $ layer = new Imagick (); $ layer-> newImage ($ im-> getImageWidth (), $ im-> getImageHeight ( ), '#000699'); $ layer-> setImageOpacity (0.48); // overlay the image to the source image. The layer blending mode is 'exclude '$ im-> compositeImage ($ layer, imagick: COMPOSITE_EXCLUSION, 0, 0); // complete! $ Im-> writeImage ('./vintage.jpg ');
Summary
The above is how to use php_imagick to achieve the retro effect. The article introduces the sample code in detail. Interested friends can easily understand the code by tapping on the code, I hope the content of this article will help you in your study or work. If you have any questions, you can leave a message.