Jump to content

Imagick


atl_andy

Recommended Posts

I'm trying to figure out how Imagick works and, after searching Google, the only information I can find is a couple of tutorials.  They don't get into the meat of the subject.  I have been successful in reading a directory and writing a picture to a new directory.  The issue I'm having is using the new picture after it is written to a directory.

 

My simple example will create a thumbnail of a picture and display it on the screen.

$dh = opendir('/var/www/images/');
while ($file = readdir($dh)) {
  if ($file != "." and $file != ".." and is_file($file)) {
    $img = new Imagick();
    $img->readImage($file);
    if ($img) {
      $img->thumbnailImage(150,150, false);
      $img->writeImage('/var/www/images/thumbs/tn.jpg');
      header("Content-type: image/jpg");
      echo $img;

    }
    $img->destroy();
  }
}
closedir($dh);

 

But when I try to use the image, nothing displays:

<img src="/var/www/images/tn.jpg" />

 

I'm not sure if it's a permissions issue, the new file is owned by the web server:

-rw-r--r-- 1 www-data www-data 30895 2009-12-26 10:18 tn.jpg

 

The file opens fine in GIMP.  Any suggestions?  My goal is to create an admin feature on a site so that images are uploaded and resized to thumbnails and displayed in a gallery.  I would like to avoid using a 3rd party script so I can learn something new other than tweaking someone else's script.

 

 

Link to comment
https://forums.phpfreaks.com/topic/186381-imagick/
Share on other sites

thanks teamatomic, that worked

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link type="text/css" href="test.css" rel="stylesheet" />
</head>
<body>
  <div id="img">
    <img src="http://localhost/images/thumbs/tn.jpg" />
  </div>
</body>
</html>

 

Link to comment
https://forums.phpfreaks.com/topic/186381-imagick/#findComment-984269
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.