略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Imagick::addImage

2024-11-15

Imagick::addImage

(PECL imagick 2, PECL imagick 3)

Imagick::addImageAdds new image to Imagick object image list

说明

public Imagick::addImage(Imagick $source): bool

Adds new image to Imagick object from the current position of the source object. After the operation iterator position is moved at the end of the list.

参数

source

The source Imagick object

返回值

成功时返回 true

错误/异常

错误时抛出 ImagickException。

add a noteadd a note

User Contributed Notes 1 note

up
3
bernie at dakotanetwork dot com
10 years ago
create a favicon.ico with multiple resolutions

<?php

$src_img
= new Imagick("src_img.png");
$icon = new Imagick();
$icon->setFormat("ico");

$geo=$src_img->getImageGeometry();

$size_w=$geo['width'];
$size_h=$geo['height'];

if (
128/$size_w*$size_h>128) {
 
$src_img->scaleImage(128,0);
} else {
 
$src_img->scaleImage(0,128);
}

$src_img->cropImage(128, 128, 0, 0);

$clone = $src_img->clone();
$clone->scaleImage(16,0);           
$icon->addImage($clone);

$clone = $src_img->clone();
$clone->scaleImage(32,0);           
$icon->addImage($clone);

$clone = $src_img->clone();
$clone->scaleImage(64,0);           
$icon->addImage($clone);

$clone = $src_img->clone();
$clone->scaleImage(128,0);   
$icon->addImage($clone);

$icon->writeImages("favicon.ico", true);

$src_img->destroy();
$icon->destroy();
$clone->destroy();

?>

官方地址:https://www.php.net/manual/en/imagick.addimage.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3