PHP uses the imagick extension to synthesize images. [add imagick extension download ],

Source: Internet
Author: User
Tags imagemagick

PHP uses the imagick extension to synthesize images. [add imagick extension download ],

This article describes two methods for merging Images Based on imagick extension in PHP. We will share this with you for your reference. The details are as follows:

Method 1: compositeimages

/*** Function: merged image * @ param string $ output_url save path * @ param string $ img_type save type * @ param integral $ line_num number of images displayed per line * @ param array $ logo_info each merged image (All dimensions are required to be uniform) * @ param array $ img_list absolute path of the image to be merged ** @ return void */public function generate ($ output_url, $ img_type, $ line_num, $ logo_info, $ img_list = array () {// calculates the number of rows in the image. $ lines = ceil (count ($ img_list)/$ line_num ); $ bg_width = ($ logo_info ['width'] + $ logo_info ['line _ width']) * $ line_num; $ bg_height = ($ logo_info ['height'] + $ logo_info ['line _ height']) * $ lines; // create a canvas $ canvas = new Imagick (); $ canvas-> newimage ($ bg_width, $ bg_height, 'white'); $ canvas-> setimageformat ($ img_type); $ I = $ j = 0; foreach ($ img_list as $ item) {$ im = new Imagick ($ item ); $ x = $ logo_info ['line _ width'] * 2 + $ I * $ logo_info ['width']; $ y = $ logo_info ['line _ height'] * 2 + $ j * $ logo_info ['height']; // $ canvas-> compositeimage ($ im-> getimage (), Imagick: COMPOSITE_OVER, $ x, $ y); $ canvas-> compositeimage ($ im, $ im-> getImageCompose (), $ x, $ y); if ($ I + 1) % $ line_num = 0) {$ I = 0; $ j ++;} else {$ I ++;} // unset ($ im); $ im-> destroy ();} $ canvas-> writeimage ($ output_url); // destroy the object $ canvas-> destroy ();}

Method 2: combineimages

/*** Function: merged image * @ param string $ output_url save path * @ param string $ img_type save type * @ param integral $ line_num number of images displayed per line * @ param array $ logo_info each merged image (All dimensions are required to be uniform) * @ param array $ img_list absolute path of the image to be merged ** @ return void */public function generate ($ output_url, $ img_type, $ line_num, $ logo_info, $ img_list = array () {// calculates the number of rows in the image. $ lines = ceil (count ($ img_list)/$ line_num ); $ bg_width = ($ logo_info ['width'] + $ logo_info ['line _ width']) * $ line_num; $ bg_height = ($ logo_info ['height'] + $ logo_info ['line _ height']) * $ lines; // create a canvas $ canvas = null; $ canvas = new Imagick (); $ canvas-> newimage ($ bg_width, $ bg_height, 'white'); $ I = $ j = 0; foreach ($ img_list as $ item) {$ im = null; $ im = new Imagick ($ item); // $ canvas-> readImage ($ item ); $ canvas-> addimage ($ im); $ im-> clear (); $ im-> destroy ();} // $ canvas-> flattenImages (); $ canvas-> combineImages (Imagick: CHANNEL_ALL); $ canvas-> writeimage ($ output_url); // destroy the object $ canvas-> clear (); $ canvas-> destroy ();}

I personally think method 2 is more efficient

Attachment: Download imagick components of php5.2.17, php5.3.18, and php5.4.8 in windows

1. I have successfully installed PHP5.2.17 and used the out-of-the-stars PHP5.2.17 to directly install the program. Download The imagick version as follows:

Click hereDownload from this site.

Contains imagemagick without installing anything, copy the php_imagick_st-Q16.dll directly to the c: \ php \ ext directory
Then add to the php. ini extension: extension = the simplest and greener method of php_imagick_st-Q16.dll
Ps: there are also php_imagick_st-Q8.dll (8 colors), php_imagick_dyn-Q16.dll (need to install imagemagick) there is no need to care about them

PHP5.2.17 this site:

32-bit: http://www.bkjia.com/softs/26087.html

64-bit: http://www.bkjia.com/softs/479475.html

2. You must install imagemagick in PHP5.3.18 and there is no available single-file dll.

1) official:

Http://www.imagemagick.org/download/binaries/ImageMagick-6.8.0-4-Q16-windows-dll.exe

2) download php_imagick in your php installation mode

Thread security:

Click hereDownload from this site.

Copy to the c: \ php \ ext directory and add extensions such as extension = php_imagick_nts.dll.

3. You must install imagemagick in PHP5.4.8 and there is no available single-file dll.

1) official:

Http://www.imagemagick.org/download/binaries/ImageMagick-6.8.0-4-Q16-windows-dll.exe

2) download php_imagick in your PHP installation mode

Wireless route security:

Click hereDownload from this site.

Copy to the c: \ php \ ext directory and add extensions such as extension = php_imagick.dll.

I have tested the above installation. I have installed iis or Apache to restart the server, and then check phpinfo to see if there is any imagick. If not, check the permission or try again.

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.