/** * This function create, if necessary, an thumbnail of a strip * * @param string $src The original path of strip * @param string $dest The thumbnail path of strip * @throws Exception If the folder for the thumbnail doesn't exist, an exception is throwed * @return boolean True if the thumbnail is created, False else */ function createThumb($src, $dest) { // check if the thumb exist if (file_exists($dest) === true) { $original_time = filemtime($src); $thumbnail_time = filemtime($dest); // if the thumb is created after the original, it's ok if ($original_time < $thumbnail_time) { return true; } } // check if the directory for thumbnail exist or create it if (checkDirAndCreate(Config::getThumbFolder()) === false) { throw new Exception('Impossible to create thumbs folder : "' . Config::getThumbFolder() . '"'); } // calculate the width and height of thumbnail $width = Config::getThumbSize(); $size = getimagesize($src); if ($size[0] > $width) { $rapport = $size[0] / $width; $height = $size[1] / $rapport; } else { $width = $size[0]; $height = $size[1]; } $img_src = imagecreatefrompng($src); $img_dst = imagecreatetruecolor($width, $height); // Preserve alpha transparency : thank crash <http://www.php.net/manual/fr/function.imagecopyresampled.php#85038> imagecolortransparent($img_dst, imagecolorallocate($img_dst, 0, 0, 0)); imagealphablending($img_dst, false); imagesavealpha($img_dst, true); $res = imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); if (!$res) { return false; } $res = imagepng($img_dst, $dest); if (!$res) { return false; } return true; }
/** * Return the path with filename of thumbnail of the strip in PNG format * @return string the path with filename of thumbnail of the strip in PNG format * @access public */ public function getThumbSrc() { $original = $this->getFilenamePng(); $dest = Config::getThumbFolder() . '/' . pathinfo(Config::getStripFolder() . '/' . $this->getFilename(), PATHINFO_FILENAME) . '.png'; if (createThumb($original, $dest) === true) { return $dest; } else { return $original; } }