【问题标题】:What is the filepath for Image Magick image format ConversionImage Magick图像格式转换的文件路径是什么
【发布时间】:2015-11-28 20:45:39
【问题描述】:

我正在尝试使用 Image Magick PECL 将 .tif 图像转换为 jpeg。 我写的函数在下面

$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();

在这段代码的第一行如何使用post方法表单动作文件路径转换成$images变量?

【问题讨论】:

    标签: php html codeigniter imagemagick imagick


    【解决方案1】:

    形式

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

    在控制器中

    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();
    }
    

    【讨论】:

    • 我试过了,但它不工作..如果我把路径设置为$images = new Imagick('www.example.com/image.tiff'); 它工作得很好,
    • 我试过了,但是显示Fatal error: Uncaught exception 'ImagickException' with message 'Can not process empty Imagick object'
    【解决方案2】:

    由于 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);
    

    这会将路径转换为完整路径,并检测图像何时位于错误位置。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 2018-02-16
      • 1970-01-01
      相关资源
      最近更新 更多