Feature Requests #1962604 (vignettes automatiques avec GD)

This commit is contained in:
Leblanc Simon 2008-05-24 10:24:55 +00:00
commit b17a10da49
4 changed files with 80 additions and 4 deletions

View file

@ -116,7 +116,7 @@ class configuration
/** /**
* Size of the thumbnails * Size of the thumbnails
*/ */
var $thumb_size = "200px"; var $thumb_size = 200;
} }
?> ?>

View file

@ -27,6 +27,12 @@ class strip_manager
*/ */
var $strips_path = "./strips"; var $strips_path = "./strips";
/**
* Directory where to find strips thumbnail
* @var string
*/
var $strips_th_path = "./strips/th";
/** /**
* Directory where to find translations files * Directory where to find translations files
* @var string * @var string
@ -320,7 +326,11 @@ class strip_manager
// change the extension for {@link $img_src} // change the extension for {@link $img_src}
$png = explode( '.', $file); $png = explode( '.', $file);
$this->img_src = $this->strips_path.'/'.$png[0].'.png'; $this->img_src = $this->strips_path.'/'.$png[0].'.png';
$this->thumbnail = $this->strips_th_path.'/'.$png[0].'.png';
if (!$this->_getThumbnail()) {
// Error in generation of thumbnail, the thumbnail will be the original
$this->thumbnail = $this->strips_path.'/'.$png[0].'.png'; $this->thumbnail = $this->strips_path.'/'.$png[0].'.png';
}
$this->source = $svg; $this->source = $svg;
@ -372,6 +382,72 @@ class strip_manager
} }
/**
* Return the link for the thumbnail (and create the thumbnail if neccesary)
*
* @return bool True if the thumbail is created, False else
*/
function _getThumbnail()
{
// check if the thumbnail exist
if (file_exists($this->thumbnail)) {
// the file exist, check if the original is create before the thumbnail
clearstatcache();
$original_time = filemtime($this->img_src);
$thumbnail_time = filemtime($this->thumbnail);
if ($original_time >= $thumbnail_time) {
// There is a modification since the creation of thumbnail
return $this->_genThumbnail();
} else {
return true;
}
} else {
return $this->_genThumbnail();
}
}
/**
* Create the thumbnail
*
* @return bool True if the creation is OK, False else
*/
function _genThumbnail()
{
// check if the directory of thumbnail exists
if (!is_dir($this->strips_th_path)) {
return false;
}
// calculate the width and height of thumbnail
$width = $this->general->thumb_size;
$size = getimagesize($this->img_src);
if ($size[0] > $width) {
$rapport = $size[0] / $width;
$height = $size[1] / $rapport;
} else {
$width = $size[0];
$height = $size[1];
}
$img_src = imagecreatefrompng($this->img_src);
$img_dst = imagecreatetruecolor($width, $height);
$res = imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
if (!$res) {
return false;
}
$res = imagepng($img_dst, $this->thumbnail);
if (!$res) {
return false;
}
return true;
}
/** /**
* Launch {@link strips_list_get}, check the asked strip, construct naviguation menu, launch {@link strip_info_get} on it * Launch {@link strips_list_get}, check the asked strip, construct naviguation menu, launch {@link strip_info_get} on it
* @access public * @access public

View file

@ -38,7 +38,7 @@
<img class="stripbox" <img class="stripbox"
src="{general.url}/{strip.thumbnail}" src="{general.url}/{strip.thumbnail}"
title="{strip.title}" title="{strip.title}"
style="width:{general.thumb_size};" style="width:{general.thumb_size}px;"
/> />
</a> </a>
</div> </div>

View file

@ -62,7 +62,7 @@
<img class="stripbox" <img class="stripbox"
src="{general.url}/{strip.thumbnail}" src="{general.url}/{strip.thumbnail}"
title="{strip.title}" title="{strip.title}"
style="width:{general.thumb_size};" style="width:{general.thumb_size}px;"
/> />
</a> </a>
</div> </div>