PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 19, 2022

[FIXED] How can I loop imagick to show preview images of all pdf files in a folder

 September 19, 2022     imagick, php     No comments   

Issue

I have this code:

$im = new imagick($folder) . '[0]');
// convert to JPEG
$im->setImageFormat('jpg');
$im->resizeImage(290, 375, imagick::FILTER_LANCZOS, 1);
$im->setResolution( 700, 700 );
header('Content-Type: image/jpeg');
echo $im;

My question is: How do I loop this result? Any time I loop, I get header issue.


Solution

I was able to solve it. I used this method: In my loop, I called thumbnail.php as image source

<li><a href='download.php?pathname=$file'><img src='thumbnail.php?pathname=$file' style='float:left; margin-top:-10px; text-align:center; width:111px;' /></li>

Then on thumbnail.php I call my header and imagick, this way:

header('Content-Type: image/jpeg');

$im = new imagick($_GET['pathname']. '[0]');
// convert to JPEG
$im->setImageFormat('jpg');
$im->resizeImage(290, 375, imagick::FILTER_LANCZOS, 1);
$im->setResolution( 700, 700 );

echo $im;

Worked the way I like it!



Answered By - Sam Adah
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing