Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: How to upload TIFF with preview pictures?  (Read 7044 times)

0 Members and 1 Guest are viewing this topic.

smantscheff

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 21
How to upload TIFF with preview pictures?
« on: November 12, 2010, 10:23:14 am »

I'm using Coppermine 1.5.8 with ImageMagick. The latter is quite capable of handling TIFF files which I want to include in Coppermine.
I changed the filetypes table entry of image/tif(f) to "image" and can upload TIFFs just fine.
But I don't see a preview because the previews are converted from TIF to TIF which the browser cannot display.
Is there a quick and easy way to configure Coppermine to convert ALL or some types of preview pictures to JPG?
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15765
Re: How to upload TIFF with preview pictures?
« Reply #1 on: November 12, 2010, 11:18:47 am »

Seems that you're more familiar with ImageMagick than me. Have a look at include/picmgmt.inc.php. ImageMagick is executed here:
Code: [Select]
           if ($superCage->env->getMatched('OS', '/win/i')) {
                $cmd = "\"".str_replace("\\","/", $CONFIG['impath'])."convert\" -quality {$CONFIG['jpeg_qual']} {$CONFIG['im_options']} ".$resize_commands." ".$unsharp_mask." ".str_replace("\\","/" ,$src_file )." ".str_replace("\\","/" ,$im_dest_file );
                exec ("\"$cmd\"", $output, $retval);
            } else {
                $cmd = "{$CONFIG['impath']}convert -quality {$CONFIG['jpeg_qual']} {$CONFIG['im_options']} ".$resize_commands." ".$unsharp_mask." $src_file $im_dest_file";
                exec ($cmd, $output, $retval);
            }

I don't know if ImageMagick converts pictures automatically to the correct format according to the output file name extension or if you have to add a particular parameter. We have to add a check if the input file is a tiff file and a thumbnail and then adjust the execution command accordingly. Do you have a Windows or Linux server?
Logged

smantscheff

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 21
Re: How to upload TIFF with preview pictures?
« Reply #2 on: November 12, 2010, 11:28:31 am »

That's the place which I also had found. And yes, it is sufficient to add the suffix to a filename to have it converted by ImageMagick into the desired format. So the conversion will work with "convert myfile.tif thumb_myfile.tif.jpg".
But if I change the code here, will the thumbnail  name (e.g. "myfile.tif.jpg") be stored? I do not see where and how. But then the interface would use the wrong thumbnail name ("thumb_myfile.tif"). So I assume I will have to change the destination filename before. Is the resize_image function the place for that? Or does it have to happen before the call to resize_image?
I'm using ImageMagick 6.5.7 on Ubuntu Linux.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15765
Re: How to upload TIFF with preview pictures?
« Reply #3 on: November 12, 2010, 11:55:30 am »

The thumbnail name will never be stored. It is always calculated that way:
Code: [Select]
$CONFIG['thumb_pfx'] . $filename
As you might know Coppermine has also the possibility to display custom thumbnails (originally for non-images). I currently don't know if Coppermine searches for a custom thumbnail for images which has no thumbnail with the same extension.

Try to replace
Code: [Select]
if (($result = resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false", 1)) !== true) {with
Code: [Select]
            if (stripos($thumb, 'tif')) {
                $thumb_filename = basename($thumb);
                $thumb_filename = str_replace('tiff', 'tif', $thumb_filename);
                $thumb_filename = basename($thumb_filename, '.tif').'.jpg');
                $thumb = str_replace(basename($thumb), $thumb_filename, $thumb);
            }
            if (($result = resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false", 1)) !== true) {
(not tested).
Logged

smantscheff

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 21
Re: How to upload TIFF with preview pictures?
« Reply #4 on: November 12, 2010, 12:00:00 pm »

Thanks a lot for the tip. I'll come back with my test results later.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15765
Re: How to upload TIFF with preview pictures?
« Reply #5 on: November 12, 2010, 12:03:12 pm »

If the .jpg thumbnail will be successfully created but is not visible in Coppermine, we need to adjust the custom thumbnail check additionally.
Logged

smantscheff

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 21
Re: How to upload TIFF with preview pictures?
« Reply #6 on: November 12, 2010, 01:26:08 pm »

The conversion from tif to jpeg runs fine with this line:
Code: [Select]
// create jpg thumbnails from tifs
$thumb = preg_replace( '/\.tif(f)?$/i', '.jpg', $thumb);
But the thumbnails won't be displayed because the system only uses the configured thumbnail prefix for computing the name and does not use a function here. To get this straight, a function for normal and thumbnail names would have to be coded into functions.inc.php and referred to at least in
edit_one_pic.php
delete.php
picmgr.php
searchnew.php
util.php
editpics.php
pic_editor.php
update.php
functions.inc.php
picmgmt.inc.php

Before I put myself to this task I'll try a hack with the Apache rewrite module to rewrite "thumb_...tif" to "thumb_...jpg", though I do not yet know what this would do to the mime type.
Logged

smantscheff

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 21
Re: How to upload TIFF with preview pictures?
« Reply #7 on: November 12, 2010, 01:38:11 pm »

O.K., the apache hack works with the following in .htaccess:
Code: [Select]
RewriteEngine On
# beware of any dots in your filenames
RewriteRule ^thumb_([^\.]+)\.(tif|tiff|TIF|TIFF)$       thumb_$1.jpg
and the mime type (in my server) is image/jpeg, as it should.
Now the problem remains that the thumbnail is not found by the system and therefore the standard thumbnail gets displayed instead of the special one.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15765
Re: How to upload TIFF with preview pictures?
« Reply #8 on: November 12, 2010, 01:57:58 pm »

the thumbnails won't be displayed because the system only uses the configured thumbnail prefix for computing the name and does not use a function here.
Afaik thumbnail urls are always generated by using the function get_pic_url. The custom thumbnail procedure resides in that function:
Code: (include/functions.inc.php) [Select]
    } elseif (($mime_content['content'] != 'image' && $mode == 'thumb') || $system_pic) {

        $thumb_extensions = array(
            '.gif',
            '.png',
            '.jpg'
        );

        // Check for user-level custom thumbnails
        // Create custom thumb path and erase extension using filename; Erase filename's extension

        if (array_key_exists('url_prefix', $pic_row)) {
            $custom_thumb_path = $url_prefix[$pic_row['url_prefix']];
        } else {
            $custom_thumb_path = '';
        }

        $custom_thumb_path .= $pic_row['filepath'] . (array_key_exists($mode, $pic_prefix) ? $pic_prefix[$mode] : '');

        $file_base_name = str_replace('.' . $mime_content['extension'], '', basename($pic_row['filename']));

        // Check for file-specific thumbs
        foreach ($thumb_extensions as $extension) {
            if (file_exists($custom_thumb_path . $file_base_name . $extension)) {
                $filepathname = $custom_thumb_path . $file_base_name . $extension;
                break;
            }
        }

Changing
Code: [Select]
    } elseif (($mime_content['content'] != 'image' && $mode == 'thumb') || $system_pic) {to
Code: [Select]
    } elseif ((($mime_content['content'] != 'image' || in_array($mime_content['extension'], array('tif', 'tiff')) && $mode == 'thumb') || $system_pic) {may do the trick (without the apache hack).
Logged

smantscheff

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 21
Re: How to upload TIFF with preview pictures?
« Reply #9 on: November 13, 2010, 11:25:29 am »

Yes, your suggestion works. Thanks a lot.
Some problems remain:
1) When deleting the image the thumbnail with the JPG extension remains. If the users tries to upload another file version of the deleted file with the same name, the old thumbnail will be used. This is a rather pathological case, but Murphy's Law guarantees it will happen.
2) Intermediate formats are served as .tif. A similar mechanism has to be applied to them, first converting the intermediate format to .jpg and then serving .jpg instead of .tif.
I assume the conversion can be done with

    $thumb = $CONFIG['fullpath'] . $filepath . $CONFIG['thumb_pfx'] . $filename;
    $orig = $CONFIG['fullpath'] . $filepath . $CONFIG['orig_pfx'] . $filename;
   
Logged

smantscheff

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 21
Re: How to upload TIFF with preview pictures?
« Reply #10 on: November 13, 2010, 11:52:02 am »

[Please disregard my prior message, I hit the send key accidentally.]
Yes, your suggestion works. Thanks a lot.
Some problems remain:

1) When deleting the image the thumbnail with the JPG extension remains. If the users tries to upload another file version of the deleted file with the same name, the old thumbnail will be used. This is a rather pathological case, but Murphy's Law guarantees it will happen.

2) Intermediate formats are served as .tif. A similar mechanism has to be applied to them, first converting the intermediate format to .jpg and then serving .jpg instead of .tif.
I assume the conversion can be done with
[include/picmgmt.inc.php]
Code: [Select]
//original code
    $thumb = $CONFIG['fullpath'] . $filepath . $CONFIG['thumb_pfx'] . $filename;
    $normal = $CONFIG['fullpath'] . $filepath . $CONFIG['normal_pfx'] . $filename;
// added code for .tif -> .jpg conversion
    $thumb = preg_replace( '/\.tif(f)?$/i', '.jpg', $thumb);
    $normal = preg_replace( '/\.tif(f)?$/i', '.jpg', $normal);
I do not understand yet how to modify functions.inc.php so that *any* occurence of .tif files except for the original one can be replaced with .jpg. Maybe you could help me there?

3) I will have to add some code which displays a download link instead of the fullsize picture. I did this in themes.inc.php with the following patch:
Code: [Select]
-    if ($CONFIG['transparent_overlay'] == 1) {
+    if (preg_match('/\.tif(f)?$/i', $imagedata['path'])) {
+      $fullsize_html = 'Dieses Bild steht im Format TIF. Das kann vom Browser nicht angezeigt werden.
+               Klicken Sie bitte mit der rechten Maustaste auf <a href="'
+               . htmlspecialchars($imagedata['path'])
+               . '">diesen Link</a> und w&auml;hlen Sie "Ziel speichern unter", um die Bilddatei auf Ihrem Computer zu speichern und weiter zu verarbeiten.';
+    } else if ($CONFIG['transparent_overlay'] == 1) {
[Yes I know it's quick and dirty.]
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15765
Re: How to upload TIFF with preview pictures?
« Reply #11 on: November 15, 2010, 01:55:03 pm »

1) When deleting the image the thumbnail with the JPG extension remains. If the users tries to upload another file version of the deleted file with the same name, the old thumbnail will be used. This is a rather pathological case, but Murphy's Law guarantees it will happen.
We have 2 possibilities imo:
1. delete all thumbnails that may be the custom thumbnail (= maybe delete thumbnails that are used for other files with the same name, but other extension)
2. remove the
Code: (include/picmgmt.inc.php) [Select]
if (!file_exists($thumb)) {check (= always overwrite existing thumbnails).

I do not understand yet how to modify functions.inc.php so that *any* occurence of .tif files except for the original one can be replaced with .jpg. Maybe you could help me there?
Basically Coppermine displays all uploaded files with the help of the function get_pic_url. So an appropriate regex before that line should work:
Code: (include/functions.inc.php) [Select]
$localpath = $pic_row['filepath'] . $pic_prefix[$mode] . $pic_row['filename'];
Logged
Pages: [1]   Go Up
 

Page created in 0.02 seconds with 20 queries.