php imagick 扩张合成图片的两张方法
php imagick 扩展合成图片的两张方法
方法一: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(); }
方法二: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(); }
个人认为方法二效率更高

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The canvas arrow plug-ins include: 1. Fabric.js, which has a simple and easy-to-use API and can create custom arrow effects; 2. Konva.js, which provides the function of drawing arrows and can create various arrow styles; 3. Pixi.js , which provides rich graphics processing functions and can achieve various arrow effects; 4. Two.js, which can easily create and control arrow styles and animations; 5. Arrow.js, which can create various arrow effects; 6. Rough .js, you can create hand-drawn arrows, etc.

The versions of html2canvas include html2canvas v0.x, html2canvas v1.x, etc. Detailed introduction: 1. html2canvas v0.x, which is an early version of html2canvas. The latest stable version is v0.5.0-alpha1. It is a mature version that has been widely used and verified in many projects; 2. html2canvas v1.x, this is a new version of html2canvas.

The details of the canvas clock include clock appearance, tick marks, digital clock, hour, minute and second hands, center point, animation effects, other styles, etc. Detailed introduction: 1. Clock appearance, you can use Canvas to draw a circular dial as the appearance of the clock, and you can set the size, color, border and other styles of the dial; 2. Scale lines, draw scale lines on the dial to represent hours or minutes. Position; 3. Digital clock, you can draw a digital clock on the dial to indicate the current hour and minute; 4. Hour hand, minute hand, second hand, etc.

The tkinter canvas attributes include bg, bd, relief, width, height, cursor, highlightbackground, highlightcolor, highlightthickness, insertbackground, insertwidth, selectbackground, selectforeground, xscrollcommand attributes, etc. Detailed introduction

How to use canvas to draw charts and animation effects in uniapp requires specific code examples 1. Introduction With the popularity of mobile devices, more and more applications need to display various charts and animation effects on the mobile terminal. As a cross-platform development framework based on Vue.js, uniapp provides the ability to use canvas to draw charts and animation effects. This article will introduce how uniapp uses canvas to achieve chart and animation effects, and give specific code examples. 2. canvas

According to news from this website on February 14, Yahoo LINE announced today that a Korean outsourcing company was illegally accessed, and the information of about 57,000 LINE employees may have been leaked. It has not yet been confirmed whether any user or business partner information has been leaked. Following the leakage of user information by the LINE app in November 2023, the company's lax information management was exposed one after another. According to Yahoo LINE officials, between August and November 2023, two outsourcing Korean companies received unauthorized access and third-party intrusions, and the email addresses, phone numbers and photos of 57,611 employees were potentially leaked. It has not yet been confirmed whether secondary damage was caused by the use of employee information. Yahoo LINE announces its service in November 2023

Explore the Canvas framework: To understand what are the commonly used Canvas frameworks, specific code examples are required. Introduction: Canvas is a drawing API provided in HTML5, through which we can achieve rich graphics and animation effects. In order to improve the efficiency and convenience of drawing, many developers have developed different Canvas frameworks. This article will introduce some commonly used Canvas frameworks and provide specific code examples to help readers gain a deeper understanding of how to use these frameworks. 1. EaselJS framework Ea

Invalid styles include CSS3 animations and transitions, CSS filter effects, CSS3 complex graphics and paths, some CSS3 features, pseudo elements and some CSS features, Z-index, background images and gradients, etc. Detailed introduction: 1. CSS3 animation and transition: html2canvas may not fully capture CSS3 animation and transition effects. Although attempts will be made to capture the final style, these animations and transitions may be lost during the conversion process; 2. CSS filter effects: filters such as blur and shadow may not be retained during the conversion process, etc.
