The method of using Php_imagick to realize the retro effect _php example

Source: Internet
Author: User
Introduction

Php_imagick is a php extension that can be used by PHP to invoke the ImageMagick feature, and this extension allows PHP to have the same functionality as ImageMagick.
ImageMagick is a powerful, stable and free toolset and development package that can be used to read, write, and process image files in more than 185 basic formats, including popular TIFF, JPEG, GIF, PNG, PDF, and PHOTOCD formats. With ImageMagick, you can dynamically generate images based on the needs of your Web application, and you can resize, rotate, sharpen, subtract, or add effects to a (or a group of) images and save the results of the operation in the same format or other format.

Php_imagick Program Examples

1. Create a thumbnail image and display it

<?phpheader (' content-type:image/jpeg '); $image = new Imagick (' image.jpg ');//If 0 is provided as a width or height para meter,//aspect ratio is maintained$image->thumbnailimage (0); Echo $image;? >

2. Create a thumbnail in a directory and save

<?php$images = new Imagick (Glob (' images/*. JPG ') ($images as $image) {//providing 0 forces thumbnailimage to maintain aspect ratio$image->thumbnailimage (1024,0);} $images->writeimages ();? >

3. Animated image of the thumbnail gif

<?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 (+);/* Set the virtual canvas to correct size */$frame-> ; Setimagepage (50, 50, 0, 0);} /* Notice writeimages instead of Writeimage */$im->writeimages ("Example_small.gif", true); >

The method of using Php_imagick to realize the retro effect

Look first.


Retro effect Show

To achieve the above results, we first use Photoshop to implement the following steps.

Open Original

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 is excluded

Merging layers

With PHP code, you just need to follow the above steps to achieve, 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 original, layer blending mode ' Soft Light ' $im->compositeimage ($layer, imagick::composite_softlight, 0, 0);//new layer, using the color ' #000699 ' padding, opacity set to ' 48% ' $layer = New Imagick (); $layer->newimage ($im->getimagewidth (), $im->getimageheight (), ' #000699 '); $layer Setimageopacity (0.48);//overlay to original, layer blending mode ' exclude ' $im->compositeimage ($layer, imagick::composite_exclusion, 0, 0);//Finish! $im->writeimage ('./vintage.jpg ');

Summarize

The above is the use of Php_imagick to achieve the retro effect of the method, the article through the sample code introduced or very detailed, interested friends of their own knocking on the code more convenient to understand, I hope the content of this article on everyone's study or work can bring certain help, if there is doubt you can message exchange.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.