简体   繁体   English

Image Magick图像格式转换的文件路径是什么

[英]What is the filepath for Image Magick image format Conversion

I am trying to convert a .tif image into jpeg using Image Magick PECL. 我正在尝试使用Image Magick PECL将.tif图像转换为jpeg。 the function i wrote is below 我写的功能如下

$images = new Imagick('$_FILE['img']');
  foreach($images as $i=>$image) {
    // Providing 0 forces thumbnail Image to maintain aspect ratio
    $image->thumbnailImage(768,0);
    $image->writeImage("uploads/page".$i.".jpg");
    echo "<img src='page$i.jpg' alt='images' ></img>";
  }
  $images->clear();

in the first line of this code how to use post method form action file path into $images variable? 在此代码的第一行中,如何使用post方法将动作文件路径转换为$ images变量?

in form 通知

<form action="<?php echo base_url().'contoller/change_method'?>" method="post" enctype="multipart/form-data">
    <input type="file" name="img">
</form>

in Controller 在控制器中

public function change_method()
{
    $images = new Imagick('$_FILE['img']');
    foreach($images as $i=>$image) 
    {
        // Providing 0 forces thumbnail Image to maintain aspect ratio
        $image->thumbnailImage(768,0);
        $image->writeImage("uploads/page".$i.".jpg");
        echo "<img src='page$i.jpg' alt='images' ></img>";
    }
    $images->clear();
}

Because Imagick passes all the work to ImageMagick, and ImageMagick can similarly delegate the work to other proceses, you should convert the path to the full path using the realpath function. 因为Imagick将所有工作都传递给ImageMagick,并且ImageMagick可以类似地将工作委托给其他进程,所以您应该使用realpath函数将路径转换为完整路径。

$realPath = realpath($_FILE['img']);
if ($realPath === false) {
    throw new \Exception("File was not located at ".$_FILE['img']);
}
$imagick = new Imagick($realPath);

This will both convert the path to the full path, as well as detect when the image is in the wrong place. 这样既可以将路径转换为完整路径,也可以检测图像何时放置在错误的位置。

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

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