2

The following code works like a charm:

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

But what if I need to include that image in an existing html page? If I remove the header image/jpeg it shows the image as text. I'm looking for an ImageMagick method that can do the trick. Any advice?

raz3r
  • 3,071
  • 8
  • 44
  • 66
  • possible duplicate of [PHP-Imagemagick image display](http://stackoverflow.com/questions/6087569/php-imagemagick-image-display) – Koen. Aug 27 '15 at 20:33

3 Answers3

2

You would have the code above on a seperate page called something like image.php ( note you will need to remove the header part ).

Then where you want it on the main page use:

<img src="image.php">
Bonzo
  • 5,169
  • 1
  • 19
  • 27
  • I thought about that but the page index is not always 0, I tryed something like `image.php?page=0` but it does not work in the img tag. – raz3r Dec 07 '12 at 08:18
  • Well my idea of image.php?page=0 actually worked. I don't know why it wasn't working few minutes ago. IT mysteries I guess. Thank you all guys :) – raz3r Dec 07 '12 at 08:43
  • I have used the method above of putting the image name in the variable as well and can also confirm it works. I do not know if you are supposed to do it that way though ! – Bonzo Dec 07 '12 at 10:32
1

Write the image in the filesystem, and then output a HTML page with a <img> tag:

<?php
$im = new imagick('file.pdf[0]');
$im->setImageFormat('jpg');
$im->writeImage('/var/www/domain/image/something.png');

echo "<img src='/image/something.png'>";

Note that the file must be in a publicly accessible directory

Raffaele
  • 20,627
  • 6
  • 47
  • 86
  • I'd like to avoid that if possible, also because every time the page is called it will write on the disk and I am quite sure page will be called plenty of time during the day. Also my dad has your same name :) – raz3r Dec 07 '12 at 08:23
0

You will have to call this php page in a img tag

Kirtan
  • 120
  • 1
  • 6