Creating thumbnails with Imagecache module API

Murz - May 12, 2008 - 13:47
Project:Upload previews
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

I look that Upload preview module have own system of creating and storing thumbnails. Drupal 5 & 6 have module Imagecache that give functionality to create and control previews with confuguration interface and API for other modules. I think that there are good way to use this module API in upload_preview module.

#1

kkaefer - May 16, 2008 - 18:36

In fact, this is on my to-do list. It probably won't happen for the D5 version, but as soon as I port the module to Drupal 6, I will most likely make it depend on imagecache 2 to use it's reliable thumbnail creation system.

#2

HansBKK - September 23, 2008 - 07:43

+1

a whole other set of thumbnails being autogenerated into my filesystems is annoying when I’ve already got Image and Imagecache going…

And if it takes a year, never mind about backporting, but I think a lot of us will still be on D5 at least that long. . .

#3

rmiddle - October 9, 2008 - 04:24

Not sure I want to use imagecache. I might look at using it if it is there but that module has huge requirement and I don't want to use it unless there is no other choice.

Thanks
Robert

#4

HansBKK - October 9, 2008 - 06:36

Thanks for a great module Robert, this issue's a minor nit since you allow setting the lifetime down to a day.

Taking advantage of it for systems that have it already loaded would be ideal, but seems like a lot of trouble just to satisfy filesystem neatfreaks, I can't image the performance hit's significant unless someone's doing a very popular Flickr-clone on Drupal, and then they're probably not using core upload :)

For those who haven't checked it out, Imagecache's a beautiful thing - it's a bit like the size of my site's images are now under control of the theme - if I decide I will expand or contract the width of a column, just change the preset's settings and baddaboom, don't have to touch the original nodes nor the original image files themselves.

Whatever image handling system finally makes it into core (D7?) I'd give pretty good odds on it making use of imagecache.

I never considered myself a gambling man, until I got involved with computers :)

#5

open-keywords - October 9, 2008 - 07:44
Title:Creating thumbnails with Imagecache module API» Creating thumbnails of PDF documents

I would suggest also to look at automated thumbnail generation for documents.

I found this example for PDF
http://chirale.wordpress.com/2008/06/06/pdf-cover-thumbnails-for-attache...

Expanding to as many "office" document formats as possible would be great for document management usage !

#6

HansBKK - October 9, 2008 - 09:02

How often are you uploading a document from a whole batch of similarly-named files and need to see the thumbnail to decide which one to pick?

This only happens to me with image files, and is the only reason (AFAICS) for this module's existence.

#7

open-keywords - October 9, 2008 - 16:00

Thumbnails are useful when browsing the uploaded documents: users of the site can preview the PDF to choose which one they want to download !

#8

HansBKK - October 10, 2008 - 00:49

But this module is only for helping the content author who is UPLOADing images.

It is usually a good idea to be familiar with a module before posting in the issue queue.

#9

HansBKK - October 19, 2008 - 13:02
Title:Creating thumbnails of PDF documents» Creating thumbnails with Imagecache module API

Setting title back to original intent

#10

chirale - October 22, 2008 - 09:08

Hi, I've updated my blog article linked here to include the code I use daily on some sites:

<?php
function file_preview(&$file, $pages = Array(1)) {
  
$allowed_mime = array("application/pdf");
   if(
in_array(strtolower($file->filemime),$allowed_mime)){
   
$local_src_path = getcwd() . "/" . $file->filepath;
   
$local_dest_path = getcwd() . "/" . file_directory_path() . "/" . file_preview_path($file->filename);
      
# use ImageMagick functions provided by image.module (Drupal 5.x)
   
$imagemagick = getcwd() . '/includes/' . 'image.imagemagick.inc';
   
# create thumbnail only when needed
   
if(!file_exists($local_dest_path) && file_exists($imagemagick)){
        include_once(
$imagemagick);
       
_image_imagemagick_convert($local_src_path.'[0]', $local_dest_path, array('-colorspace RGB'));
       
# all can read thumbnail files
       
if(file_exists($local_dest_path))
           
chmod($local_dest_path, 0777);
    }
    return
file_preview_path($file->filename);
    }
    else{
    return
FALSE;
    }
}
?>

Here I use ImageMagick wrappers provided by image.module (on Drupal 5.x) because ImageAPI wasn't yet stable when I write this piece of code: if anyone can suggest a ImageAPI alternative, a module_exists control could allow both cases.

$pages arg is not used yet, that "[0]" means "print only the first page" of a PDF, ideally $pages should contains something like array(1,5,8) and a foreach on _image_imagemagick_convert could create multiple thumbnails.

#11

frankiedesign - May 12, 2009 - 05:30

If someone is interested.. I've created some kind of very small patch for the imagecache.module on D6 that allows it to create PDF (and PS?) thumbnails by using the imagecache_actions module. Seems to me, that is does the same as the code above???

It's here...

 
 

Drupal is a registered trademark of Dries Buytaert.