Table of Contents
php imagick extends two methods of compositing images
Home Backend Development PHP Tutorial php imagick extends two methods of compositing images_PHP tutorial

php imagick extends two methods of compositing images_PHP tutorial

Jul 13, 2016 am 10:11 AM
picture method

php imagick extends two methods of compositing images


Method 1: compositeimages

/**
     *  function: 合成图片
     * @param  string      $output_url 图片保存路径
     * @param  string      $img_type   图片保存类型
     * @param  integral    $line_num   每行显示图片数量
     * @param  array       $logo_info  每张待合成图片的信息(要求所有尺寸统一)
     * @param  array       $img_list  待合成的图片绝对路径
     * 
     * @return void
     */
    public function generate($output_url, $img_type, $line_num, $logo_info, $img_list=array()) {

        //计算图片有多少行
        $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;

        //构建画布
        $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);

        //销毁对象
        $canvas -> destroy();
    }
Copy after login



Method 2: combineimages

/**
     *  function: 合成图片
     * @param  string      $output_url 图片保存路径
     * @param  string      $img_type   图片保存类型
     * @param  integral    $line_num   每行显示图片数量
     * @param  array       $logo_info  每张待合成图片的信息(要求所有尺寸统一)
     * @param  array       $img_list  待合成的图片绝对路径
     * 
     * @return void
     */
    public function generate($output_url, $img_type, $line_num, $logo_info, $img_list=array()) {

        //计算图片有多少行
        $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;
        //构建画布
        $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);

        //销毁对象
        $canvas -> clear();
        $canvas -> destroy();
    }
Copy after login

Personally, I think method 2 is more efficient

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/925220.htmlTechArticlephp imagick Two methods to extend composite images Method 1: compositeimages /** * function: composite image* @param string $output_url Image saving path* @param string $img_type Image...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel. How to write a novel in the Tomato Free Novel app. Share the tutorial on how to write a novel in Tomato Novel. Mar 28, 2024 pm 12:50 PM

Tomato Novel is a very popular novel reading software. We often have new novels and comics to read in Tomato Novel. Every novel and comic is very interesting. Many friends also want to write novels. Earn pocket money and edit the content of the novel you want to write into text. So how do we write the novel in it? My friends don’t know, so let’s go to this site together. Let’s take some time to look at an introduction to how to write a novel. Share the Tomato novel tutorial on how to write a novel. 1. First open the Tomato free novel app on your mobile phone and click on Personal Center - Writer Center. 2. Jump to the Tomato Writer Assistant page - click on Create a new book at the end of the novel.

How to enter bios on Colorful motherboard? Teach you two methods How to enter bios on Colorful motherboard? Teach you two methods Mar 13, 2024 pm 06:01 PM

Colorful motherboards enjoy high popularity and market share in the Chinese domestic market, but some users of Colorful motherboards still don’t know how to enter the bios for settings? In response to this situation, the editor has specially brought you two methods to enter the colorful motherboard bios. Come and try it! Method 1: Use the U disk startup shortcut key to directly enter the U disk installation system. The shortcut key for the Colorful motherboard to start the U disk with one click is ESC or F11. First, use Black Shark Installation Master to create a Black Shark U disk boot disk, and then turn on the computer. When you see the startup screen, continuously press the ESC or F11 key on the keyboard to enter a window for sequential selection of startup items. Move the cursor to the place where "USB" is displayed, and then

How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? Where is the automatically saved image when posting? How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? Where is the automatically saved image when posting? Mar 22, 2024 am 08:06 AM

With the continuous development of social media, Xiaohongshu has become a platform for more and more young people to share their lives and discover beautiful things. Many users are troubled by auto-save issues when posting images. So, how to solve this problem? 1. How to solve the problem of automatically saving pictures when publishing on Xiaohongshu? 1. Clear the cache First, we can try to clear the cache data of Xiaohongshu. The steps are as follows: (1) Open Xiaohongshu and click the "My" button in the lower right corner; (2) On the personal center page, find "Settings" and click it; (3) Scroll down and find the "Clear Cache" option. Click OK. After clearing the cache, re-enter Xiaohongshu and try to post pictures to see if the automatic saving problem is solved. 2. Update the Xiaohongshu version to ensure that your Xiaohongshu

How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) How to recover deleted contacts on WeChat (simple tutorial tells you how to recover deleted contacts) May 01, 2024 pm 12:01 PM

Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

How to post pictures in TikTok comments? Where is the entrance to the pictures in the comment area? How to post pictures in TikTok comments? Where is the entrance to the pictures in the comment area? Mar 21, 2024 pm 09:12 PM

With the popularity of Douyin short videos, user interactions in the comment area have become more colorful. Some users wish to share images in comments to better express their opinions or emotions. So, how to post pictures in TikTok comments? This article will answer this question in detail and provide you with some related tips and precautions. 1. How to post pictures in Douyin comments? 1. Open Douyin: First, you need to open Douyin APP and log in to your account. 2. Find the comment area: When browsing or posting a short video, find the place where you want to comment and click the "Comment" button. 3. Enter your comment content: Enter your comment content in the comment area. 4. Choose to send a picture: In the interface for entering comment content, you will see a "picture" button or a "+" button, click

How to make ppt pictures appear one by one How to make ppt pictures appear one by one Mar 25, 2024 pm 04:00 PM

In PowerPoint, it is a common technique to display pictures one by one, which can be achieved by setting animation effects. This guide details the steps to implement this technique, including basic setup, image insertion, adding animation, and adjusting animation order and timing. Additionally, advanced settings and adjustments are provided, such as using triggers, adjusting animation speed and order, and previewing animation effects. By following these steps and tips, users can easily set up pictures to appear one after another in PowerPoint, thereby enhancing the visual impact of the presentation and grabbing the attention of the audience.

What should I do if the images on the webpage cannot be loaded? 6 solutions What should I do if the images on the webpage cannot be loaded? 6 solutions Mar 15, 2024 am 10:30 AM

Some netizens found that when they opened the browser web page, the pictures on the web page could not be loaded for a long time. What happened? I checked that the network is normal, so where is the problem? The editor below will introduce to you six solutions to the problem that web page images cannot be loaded. Web page images cannot be loaded: 1. Internet speed problem The web page cannot display images. It may be because the computer's Internet speed is relatively slow and there are more softwares opened on the computer. And the images we access are relatively large, which may be due to loading timeout. As a result, the picture cannot be displayed. You can turn off the software that consumes more network speed. You can go to the task manager to check. 2. Too many visitors. If the webpage cannot display pictures, it may be because the webpages we visited were visited at the same time.

How to arrange two pictures side by side in wps document How to arrange two pictures side by side in wps document Mar 20, 2024 pm 04:00 PM

When using WPS office software, we found that not only one form is used, tables and pictures can be added to the text, pictures can also be added to the table, etc. These are all used together to make the content of the entire document look richer. , if you need to insert two pictures into the document and they need to be arranged side by side. Our next course can solve this problem: how to place two pictures side by side in a wps document. 1. First, you need to open the WPS software and find the picture you want to adjust. Left-click the picture and a menu bar will pop up, select "Page Layout". 2. Select "Tight wrapping" in text wrapping. 3. After all the pictures you need are confirmed to be set to "Tight text wrapping", you can drag the pictures to the appropriate position and click on the first picture.

See all articles