php filemtime用于制作想象力的拇指

时间:2012-08-22 19:53:02

标签: php imagick filemtime

我正在尝试使用php filemtime在相册中查找最新添加的图像(文件夹)并使用Imagick竖起大拇指。

我知道找到最新文件夹的脚本部分实际上有效,并且还可以使用Imagick部分。将这两者放在一起就是问题所在。 这里有一群更聪明的人 - 有人可以帮助并使其发挥作用吗?

脚本看起来像这样:

<?php

/* paths to the images */
$directory  = '../i/albums';
$fdirectory = opendir("$directory");
while (false !== ($file       = readdir($fdirectory))) {
    if (($file != ".") && ($file != ".." ) && ($file != "index.php~" ) && ($file != "index.php" )) {

        $files[$file] = filemtime("$directory/$file");
    }
}
closedir($fdirectory);
clearstatcache();
arsort($files);
$i            = 0;
while ((list($key1, $val) = each($files)) && ($i <= 0))
    $newdirectory = $directory . '/' . $key1 . '/thumbs/'; /* Problem is probably here */
/* Making thumbnail starts here */
/* The object used as a canvas */
$canvas       = new imagick('../images/wood_grain_3030646.jpg');
$canvas->adaptiveResizeImage(250, 250);
$canvas->setImageFormat("png");
/* Create an empty ImagickDraw object
  (Use the defaults for the polaroid) */
$bg           = new ImagickDraw();
/* Create a few random images */
/* Imagick seems not to like  $newdirectory here */
$images       = new Imagick(glob("" . $newdirectory . "{*.jpg,*.gif,*.png}", GLOB_BRACE));
/* Loop trough images, overlay on canvas and remove the image */
foreach ($images as $key => $imag) {
    /* Thumbnail to 100x width and set background to black.
      It looks like an drop-in shadow */
    $imag->thumbnailImage(100, null);
    $imag->setImageBackgroundColor(new ImagickPixel("black"));
    /* Use a random angle */
    $angle = mt_rand(1, 45);
    if (mt_rand(1, 2) % 2 === 0) {
        $angle  = $angle * -1;
    }
    /* Create the polaroid */
    $imag->polaroidImage($bg, $angle);
    /* Composite the polaroid over the canvas */
    /* Composite to a random location */
    $canvas->compositeImage($imag, Imagick::COMPOSITE_OVER, mt_rand(10, 150), mt_rand(10, 150));
    /* Round the corners. (yes, this is all that is needed.) */
    $canvas->roundCorners(10, 10);
    /* Clone the current object */
    $shadow = $canvas->clone();
    /* Set image background color to black
      (this is the color of the shadow) */
    $shadow->setImageBackgroundColor(new ImagickPixel('black'));
    /* Create the shadow */
    $shadow->shadowImage(80, 3, 5, 5);
    /* Imagick::shadowImage only creates the shadow.
      That is why the original image is composited over it */
    $shadow->compositeImage($canvas, Imagick::COMPOSITE_OVER, 0, 0);
    /* Free some resources */
    $imag->removeImage();
    /* Add some contrast */
    $shadow->contrastImage(20);

    $shadow->writeImages("../images/polaroids/polaroids_thumb.png", true);
}
/* Display the results */
header("Content-Type: image/png");
echo $shadow;
?>

我已分别测试了Imagick部分,如果用于静态文件夹,它实际上有效。

0 个答案:

没有答案