Welcome Guest, Not a member yet? Register   Sign In
Cannot generate image preview using Servicess:image
#1

I'm trying to implement this solutiion How do I convert a PDF document to a preview image in PHP? - Stack Overflow

Essentially the user says that is possible create a preview of a pdf based on this code:

PHP Code:
<?php
$im 
= new imagick('file.pdf[0]');
$im->setImageFormat('jpg');
header('Content-Type: image/jpeg');
echo 
$im;
?>

so I tried to convert that code using the image service included in CodeIgniter 4:


PHP Code:
$im = \Config\Services::image('imagick');
        $im->withFile(ROOTPATH 'public/uploads/media/2021/05/2.pdf');
        $im->save(ROOTPATH 'public/uploads/media/2021/05/2.jpg');
        echo $im

and I got: The file is not a supported image type.

how is that possible?
Reply
#2

This has nothing to do with CodeIgniter.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Codeigniter "imagic" != Imagic
Use Imagic directly
Reply
#4

there is an example about imagick in codeigniter?
Reply
#5

If using the ImageMagick library, you must set the path to the library on your server in app/Config/Images.php.

Note

The ImageMagick handler does NOT require the imagick extension to be loaded on the server.
As long as your script can access the library and can run exec() on the server, it should work.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

(This post was last modified: 02-04-2022, 04:19 AM by demyr.)

(05-12-2021, 02:01 AM)InsiteFX Wrote: If using the ImageMagick library, you must set the path to the library on your server in app/Config/Images.php.

Note

The ImageMagick handler does NOT require the imagick extension to be loaded on the server.
As long as your script can access the library and can run exec() on the server, it should work.

Any idea about how to set this path? I feel like the documentation lacks this information.
Reply
#7

This is the only thing I can find on it plus php.net links are in the bottom link.

How do I set the path in Apache for ImageMagick so I can run from PHP system()?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB