简体   繁体   中英

What is the filepath for Image Magick image format Conversion

I am trying to convert a .tif image into jpeg using Image Magick PECL. 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?

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.

$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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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