简体   繁体   English

imagick的:从路径中打开文件,调整大小,保存到文件夹

[英]Imagick: open file from path, resize, save to folder

I'm trying to append several images together into one big image, but the first hurdle is actually just getting the image to open. 我正在尝试将几张图像一起添加到一个大图像中,但是第一个障碍实际上只是使图像打开。

I am attempting to do the following: 我正在尝试执行以下操作:

  1. Open image from path 从路径打开图像
  2. Size it with the specified dimensions 按指定尺寸调整大小
  3. Save it to the current folder 将其保存到当前文件夹

I have the following: 我有以下几点:

define('WIDTH',  600);
define('HEIGHT', 800);

$img = new Imagick();
$img->readImage('dress.jpg');
$img->writeImage('image1.png');

I can get the image to save, but I do not know where to add the WIDTH and HEIGHT definitions? 我可以保存图像,但是不知道在哪里添加WIDTHHEIGHT定义?

I tried doing the following: 我尝试执行以下操作:

$img->newImage(WIDTH, HEIGHT, $img);
$img = new Imagick();
$img->readImage('dress.jpg');

$img->resizeImage(WIDTH, HEIGHT, Imagick::FILTER_LANCZOS, 1);

$img->writeImage('image1.png');

After "creating" an image resource with new Imagick() you are "working" in that resource. 使用new Imagick() “创建”图像资源后,您正在该资源中“工作”。 readImage() reads the image which is then present in the resource - after that you can resize the resource and write it out after the work is done. readImage()读取图像,然后该图像将出现在资源中-之后,您可以调整资源大小并在完成工作后将其写出。

See the documentation for more info Imagick::resizeImage() 请参阅文档以获取更多信息Imagick :: resizeImage()

With new Imagick(WIDTH, HEIGHT) you create an image resource with an empty canvas of the given size. 使用new Imagick(WIDTH, HEIGHT)您可以使用给定大小的空白画布创建图像资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM