Update of /cvsroot/php-blog/serendipity/include
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28257/include
Modified Files:
functions_images.inc.php
Log Message:
generate thumbnails from pdf files
the implementation shows some flaws in serendipitys image handling. thumb mimetype != file mime type.
this one has a little bug: -flatten takes the last page of the pdf, the first would be much nicer. some imagemagick freaks out there who can solve that?
Index: functions_images.inc.php
===================================================================
RCS file: /cvsroot/php-blog/serendipity/include/functions_images.inc.php,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- functions_images.inc.php 5 Dec 2004 14:00:57 -0000 1.5
+++ functions_images.inc.php 5 Dec 2004 15:05:48 -0000 1.6
@@ -212,9 +212,14 @@
} else {
/*if ($serendipity["dim"] == "height") $newSize = "*x".$serendipity["thumbSize"];
else $newSize = $serendipity["thumbSize"]."x*"; */
- $newSize = $size . 'x' . $size;
- $r = array($size, $size);
- $cmd = $serendipity['convert'] . " -antialias -scale $newSize \"$infile\" \"$outfile\" 2>&1";
+ if ($ft_mime != 'application/pdf') {
+ $newSize = $size . 'x' . $size;
+ $r = array($size, $size);
+ $cmd = $serendipity['convert'] . " -antialias -scale $newSize \"$infile\" \"$outfile\" 2>&1";
+ } else {
+ $newSize = $size . 'x' . $size;
+ $cmd = $serendipity['convert'] . " -antialias -flatten -scale $newSize \"$infile\" \"$outfile.png\" 2>&1";
+ }
$res = `$cmd`;
}
}
@@ -806,6 +811,10 @@
++$x; $preview = '';
$i = @getimagesize($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . '.' . $file['thumbnail_name'] . '.' . $file['extension']);
$imgsrc = $serendipity['uploadHTTPPath'] . $file['path'] . $file['name'] . '.' . $file['thumbnail_name'] . '.' . $file['extension'];
+ if ($file['mime'] == 'application/pdf') {
+ // File is PDF -> Thumb is PNG
+ $imgsrc .= '.png';
+ }
$is_image = ( 0 === strpos(strtolower($file['mime']), "image/") );
if (file_exists($imgsrc)) {
@@ -813,7 +822,7 @@
if ($url) { $preview = '<a href="'. $url .'&serendipity[image]='. $file['id'] .'">'. $preview .'</a>'; }
}
- if (!$is_image) {
+ if (!file_exists($imgsrc)) {
$preview .= '<div class="serendipity_admin_mimetype" style="width: ' . $serendipity['thumbSize'] . 'px; height: ' . $serendipity['thumbSize'] . 'px; border: 1px solid; text-align: center;"><br /><br /><br />' . $file['mime'];
if ($url) { $preview .= '<br /><a href="' . $url . '&serendipity[image]=' . $file['id'] . '">' . $file['name'] . '.' . $file['extension'] . '</a>'; }
$preview .= '</div>';
@@ -1028,6 +1037,10 @@
$fdim = @getimagesize($file);
+ if ($ft_mime == 'application/pdf') {
+ $fdim = array(1000,1000,24, '', 'bits'=> 24, channels => '3', 'mime' => 'application/pdf');
+ }
+
if (is_array($fdim)) {
if (empty($fdim['mime'])) {
$fdim['mime'] = $ft_mime;
|