Tiff Image Display Modification Tiff Image Display Modification
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Tiff Image Display Modification

Started by Garibaldi, July 29, 2009, 10:07:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Garibaldi

I'd like to announce the availability of the Tiff Image Display Modification. This modification for Coppermine 1.4.x allows users to upload tiff images and have them be displayed just like jpgs or pngs. The way it works is it detects if the user is uploading a tiff and then converts it to a jpg, while keeping a copy of the original tiff for the user to download as well. The jpg version is then displayed in the gallery, and the original tiff is available for download via a link in the Custom User Field 2.

Requirements:
This modification requires that you use Imagemagick to handle your images as it is needed to convert the tiffs to jpgs

*NEW* - the uploaded tiffs are now deleted when you delete a picture. To add this feature and upgrade from 1.0.x, please see this post.

See the attachments for some screenshots.

A support topic for this modification is available on the Support Board.
If you are having trouble, you can enable debug on this mod by finding:
$g_debug = false;
and replacing it with:
$g_debug = true;
This will show debug output on each phase of the upload process

A bugfix from Tom can be found in this post below.

Mod History:
2009-08-03- version 1.1.0 now deletes the uploaded tiff when deleting a picture
2009-07-29- version 1.0.1 - bugfixes with multiple uploads
2009-07-29- version 1.0.0

Garibaldi

#1
Install Instructions (also available in the zip download):

###############################################
## MOD Title: Tiff Image Display
## MOD Author: Garibaldi (Garibaldi@wiscollectorcar.com) http://www.wiscollectorcar.com
## MOD Description: Allows users to upload tiff images which are then converted to jpgs for display while the orininal tiff is still available for download
## MOD Version: 1.1.0
## Installation Level: Easy
## Installation Time: 10 minutes
## Requirements: Imagemagick
## Files To Edit:2
##   delete.php
##   upload.php
## Included Files:
##   albums/tiff_downloads/
## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v3
##############################################################
## Author Notes:
## This modification requires that you use imagemagick for processing images
##
## Once this modification is applied, the user2 custom field cannot be used
## for something else except this mod. Please uninstall this mod if you
## want to use user2 again and cannot use user1, user3, or user4 instead.
##############################################################
## MOD History:
## 2009-08-03- version 1.1.0 now deletes the uploaded tiff when deleting a picture
## 2009-07-29- version 1.0.1 - bugfixes with multiple uploads
## 2009-07-29- version 1.0.0
##############################################################
## Before Adding This MOD To Your Coppermine install, You Should Back Up All Files Related To This MOD
##############################################################

#
#-----[ IN COPPERMINE ]---------------------------------
#
   Log in as an administrator and go to Config. Expand the section
   "Custom fields for image description (leave blank if unused)" and
   enter a name in "Field 2 name" like "Download Tiff". Now, expand the
   section "Files and thumbnails advanced settings" and for
   "Method for resizing images", select "Image Magick". Fill in the
   "Path to ImageMagick 'convert' utility", e.g. "/usr/bin/" . Save the new
   configuration.

#
#-----[ UPLOAD ]----------------------------------------
#
   Upload the tiff_downloads/ folder into the albums/ folderand chmod it
   to 777. It must have group read/write permissions for the tiff images
   to be uploaded

#
#-----[ OPEN ]------------------------------------------
#
   delete.php

#
#-----[ FIND ]------------------------------------------
#
   if (!is_writable($dir)) cpg_die(CRITICAL_ERROR, sprintf($lang_errors['directory_ro'], htmlspecialchars($dir)), __FILE__, __LINE__);

#
#-----[ BEFORE, ADD ]-----------------------------------
#
    // start garibaldi
    $g_query = "SELECT user2 FROM {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid'";
    $g_result = cpg_db_query($g_query);
    $g_user2 = mysql_fetch_array($g_result);
    foreach($g_user2 as $key => $value) {
   if (strpos($value, "http") === false) {
   } else {
      // if its the url, grab it and cut off the part we don't want and put on the server path
      $path = str_replace($CONFIG['ecards_more_pic_target'], "", $value);
   }
    }
    if (is_file($path)) {
       unlink($path);
    }
    // end garibaldi

#
#-----[ OPEN ]------------------------------------------
#
   upload.php

#
#-----[ FIND ]------------------------------------------
#
   $allowed_URI_boxes = NUM_URI_BOXES;
   $allowed_file_boxes = NUM_FILE_BOXES;   

#
#-----[ After, ADD ]------------------------------------
#
   // garibaldi start
   $g_debug = false;         // set this to true to see debug during upload               
   $mod_name = "Tiff Image Display";   // the name of the modification by garibaldi
   // garibaldi end

#
#-----[ FIND ]------------------------------------------
#
       $form_array[] = array($CONFIG['user_field2_name'], 'user2', 0, 255, 1);

#
#-----[ REPLACE WITH ]----------------------------------
#
   // garibaldi start
           $num_left = $_POST['numuploads'] - 1;   
           $tiffpath = "";

           if (!empty($_POST['tiffpath'])) {
         $paths = explode(";", $_POST['tiffpath']);
              $_POST['tiffpath'] = "";
         $length = count($paths);
         $tiffpath = $paths[$num_left];
         if ($tiffpath == "not") {
            $tiffpath = "";
         }
         $i = 0;
         foreach ($paths as $key => $value) {
            if ($i < $num_left) {
               $_POST['tiffpath'] .= $value . ";";
            }
            $i++;
         }
           }
           $form_array[] = array('numuploads', $num_left, 4);      // create a hidden field to show the number image we're on
           $form_array[] = array('tiffpath', $_POST['tiffpath'], 4);      // create a hidden field to show the number image we're on
          $form_array[] = array('user2', $tiffpath, 4);      // use user2 as a hidden field containing the tiff url
   // garibaldi end

#
#-----[ FIND ]------------------------------------------
#
      // Assemble the file path.
      $path_to_image = './'.$CONFIG['fullpath'].'edit/'. $prefix . $seed . '.' . $suffix;

   } while (file_exists($path_to_image));

   // Create a holder called $tempname.
   $tempname = $prefix . $seed . '.' . $suffix;

#
#-----[ REPLACE WITH ]----------------------------------
#
      // garibaldi start
      $g_debug_messages = "";                  // the debug messages
      $g_debug_messages .= "Initial Suffix: " . $suffix . "<br>";   
      $tiff_storage = './'.$CONFIG['fullpath'].'tiff_downloads/';   // the location of the tiff files on the server
      $pos = strpos($suffix,"tif");               // determine if this is a tiff image
      $isTiff = false;
      if($pos === false) {                  // if its not a tiff, proceed as normal
         // Assemble the file path.
              $path_to_jpg = './'.$CONFIG['fullpath'].'edit/'. $prefix . $seed . '.' . $suffix;
         $g_debug_messages .= "Its not a tiff image<br>";
      }
      else {                        // it is a tiff, lets create a jpg version
         // Convert the image, then assemble the file path
         $g_debug_messages .= "Its a tiff image<br>";
         $path_to_jpg = './'.$CONFIG['fullpath'].'edit/'. $prefix . $seed . '.jpg';
         $isTiff = true;
      }
                 $path_to_image = './'.$CONFIG['fullpath'].'edit/'. $prefix . $seed . '.' . $suffix;
//
            } while (file_exists($path_to_image));//
//
            // Create a holder called $tempname.//
            // $tempname = $prefix . $seed . '.' . $suffix; // garibaldi
         // garibaldi end

#
#-----[ FIND ]------------------------------------------
#
       //Now we upload the file.
       if (!(move_uploaded_file($_FILES['file_upload_array']['tmp_name'][$counter], $path_to_image))) {

      // The file upload has failed.

      $file_failure_array[] = array( 'failure_ordinal'=>$failure_ordinal, 'file_name'=> $file_name, 'error_code'=>$lang_upload_php['impossible']);

      // There is no need for further tests or action, so skip the remainder of the iteration.
      continue;

       }

#
#-----[ AFTER, ADD ]------------------------------------
#
      // garibaldi start
           // Change file permission
                @chmod($path_to_image, octdec($CONFIG['default_file_mode'])); //silence the output in case chmod is disabled

           $convert_output_arr = "";   // the output from the imagemagick call as an array
           $convert_output = "";   // the output from the imagemagick call as a string (for display)

           if ($isTiff) {
         exec("convert " . $path_to_image . " " . $path_to_jpg, $convert_output_arr);   // do the conversion to create a jpg
         $path_to_tiff = $path_to_image;               // set the tiff path
         $path_to_image = $path_to_jpg;               // update the image path to point to the jpg version
         foreach ($convert_output_arr as $key => $value) {      // create the string output of the conversion call
            $convert_output .= $value . "<br>";
             }
           }

      $g_debug_messages .= "picture_name: " . $picture_name . "<br>";
      $tiff_final_location = $tiff_storage . $seed . "." . $suffix;   // set the final location of the tiff

      // now its okay for the suffixes to be adjusted

      if ($isTiff) {                     // its a tiff, set the variables
         $suffix = "tif";
         $matches[2] = $suffix;
         if (strpos($picture_name, "tiff") == false) {
            // the extension is tif, change it to jpg
            $g_debug_messages .= "The extension is 'tif', changing it<br>";
            $picture_name = str_replace("tif", "jpg", $picture_name);

         } else {
            // the extension is tiff, change it to jpg
            $g_debug_messages .= "The extension is 'tiff', changing it<br>";
            $picture_name = str_replace("tiff", "jpg", $picture_name);
         }
         $suffix = "jpg";
         $matches[2] = "jpg";
         $matches[0] = $matches[1] . "." . $matches[2];
      }
                // Create a holder called $tempname.
           $tempname = $prefix . $seed . '.' . $suffix;
           $g_debug_messages .= "The new picture name: " . $picture_name . "<br>";

      if (copy($path_to_tiff, $tiff_final_location)) {      // if we can successfully move the tif, then proceed
         unlink($path_to_tiff);
         $g_tiff_names = $tiff_final_location;
      } else {
         $tiff_final_location = $path_to_tiff;
         $g_tiff_names = "";
      }
   
      // format the url correctly (only if its a tiff)
      if ($g_tiff_names != "") {
         if (substr($g_tiff_names,0,1) == ".") {
            $g_tiff_names = substr($g_tiff_names, 1);
         }
         if ((substr($CONFIG['site_url'], strlen($CONFIG['site_url'])-1) == "/") && (substr($g_tiff_names, 0, 1) == "/")) {
            $g_tiff_names = substr($g_tiff_names, 1);
         }
      $g_tiff_names = $CONFIG['site_url'] . $g_tiff_names;      // set the tiff url
      }
      
      if ($isTiff) {   
         $_POST['tiffpath'] .= $g_tiff_names . ";";      // update the POST info with the tiff url         
      } else {
         $_POST['tiffpath'] .= "not;";            // update the POST info with the tiff url         
      }
            
      // compile all the debug
      $g_debug_messages .= "convert output: " . $convert_output . "<br>tiff path: " . $tiff_final_location . "<br>jpg path: ";
      $g_debug_messages .= $path_to_image . "<br>picture_name: " . $picture_name . "<br>matches[0]: " . $matches[0];
      $g_debug_messages .= "<br>matches[1]: " . $matches[1] . "<br>matches[2]: " . $matches[2] . "<br>tempname: " . $tempname;
      $g_debug_messages .= "<br>Tiff POST: " . $_POST['tiffpath'];
      // garibaldi end

#
#-----[ FIND ]------------------------------------------
#
        // Prepare success data for user.
        open_form($_SERVER['PHP_SELF']); // Set the form action to this script.
        starttable("100%", $lang_upload_php['succ'], 2);
        echo "<tr><td colspan=\"2\">";
        printf ($lang_upload_php['success'], $escrow_array_count);
        echo "<br /><br />";
        echo $lang_upload_php['add'];
        echo "</td></tr>";

#
#-----[ AFTER, ADD ]------------------------------------
#
   // garibaldi start
   // send the tiff path information
   hidden_input("tiffpath", $_POST['tiffpath']);
   hidden_input("numuploads", $escrow_array_count);

   if ($g_debug) {
      echo "<tr><td><u><b>$mod_name Debug:</b></u><br>" . $g_debug_messages . "<br></td></tr>";
   }
   // garibaldi end

#
#-----[ FIND ]------------------------------------------
#
        if ($file_placement == 'no') {

            $final_message = ''.$lang_upload_php['no_place'].'<br /><br />'.$lang_upload_php['process_complete'];

        } else {

            $final_message = ''.$lang_upload_php['yes_place'].'<br /><br />'.$lang_upload_php['process_complete'];

        }

#
#-----[ REPLACE WITH ]----------------------------------
#
      // garibaldi start
                if ($file_placement == 'no') {//
      // set up some debug output
                    $final_message = ''.$lang_upload_php['no_place'].'<br />';
         if ($g_debug) {
            $final_message .= "<br /><b><u>$mod_name Debug:</u></b>";
            $final_message .= "<br />filename: $file_set[1]<br />";
            $final_message .= "tiff location: $user2<br />$g_debug_output<br />";
         }
//
          $final_message .= '<br />'.$lang_upload_php['process_complete'];
//
                } else { //
//
                    $final_message = ''.$lang_upload_php['yes_place'].'<br /><br />'.$lang_upload_php['process_complete'];//
         if ($g_debug) {
            $final_message .= "<br /><b><u>$mod_name Debug:</u></b>";
            $final_message .= "<br />filename: $file_set[1]<br />";
            $final_message .= "tiff location: $user2<br />$g_debug_output<br />";
         }
                }//
      // garibaldi end

#
#-----[ FIND ]------------------------------------------
#
   $form_array[] = array($CONFIG['user_field2_name'], 'user2', 0, 255, 1);

#
#-----[ REPLACE WITH ]----------------------------------
#
   // garibaldi start
           $num_left = $_POST['numuploads'] - 1;   
           $tiffpath = "";

           if (!empty($_POST['tiffpath'])) {
         $paths = explode(";", $_POST['tiffpath']);
              $_POST['tiffpath'] = "";
         $length = count($paths);
         $tiffpath = $paths[$num_left];
         if ($tiffpath == "not") {
            $tiffpath = "";
         }
         $i = 0;
         foreach ($paths as $key => $value) {
            if ($i < $num_left) {
               $_POST['tiffpath'] .= $value . ";";
            }
            $i++;
         }
           }
           $form_array[] = array('numuploads', $num_left, 4);      // create a hidden field to show the number image we're on
           $form_array[] = array('tiffpath', $_POST['tiffpath'], 4);      // create a hidden field to show the number image we're on
          $form_array[] = array('user2', $tiffpath, 4);      // use user2 as a hidden field containing the tiff url   // garibaldi end

#
#-----[ NOTE ]------------------------------------------
#
   Once this modification is applied, the user2 custom field cannot be used
   for something else except this mod. Please uninstall this mod if you
   want to use user2 again and cannot use user1, user3, or user4 instead.

#
#-----[ SAVE/CLOSE ALL FILES ]--------------------------
#
# EoM

Garibaldi

I'm releasing an update that includes support for deleting the uploaded tiff file when you delete a picture. To upgrade, simply follow these instructions:
#
#-----[ UPLOAD ]----------------------------------------
#
Upload the tiff_downloads/ folder into the albums/ folderand chmod it
to 777. It must have group read/write permissions for the tiff images
to be uploaded

#
#-----[ OPEN ]------------------------------------------
#
delete.php

#
#-----[ FIND ]------------------------------------------
#
if (!is_writable($dir)) cpg_die(CRITICAL_ERROR, sprintf($lang_errors['directory_ro'], htmlspecialchars($dir)), __FILE__, __LINE__);

#
#-----[ BEFORE, ADD ]-----------------------------------
#
    // start garibaldi
    $g_query = "SELECT user2 FROM {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid'";
    $g_result = cpg_db_query($g_query);
    $g_user2 = mysql_fetch_array($g_result);
    foreach($g_user2 as $key => $value) {
if (strpos($value, "http") === false) {
} else {
// if its the url, grab it and cut off the part we don't want and put on the server path
$path = str_replace($CONFIG['ecards_more_pic_target'], "", $value);
}
    }
    if (is_file($path)) {
    unlink($path);
    }
    // end garibaldi


You can download the full installation for this new version in the first post of this topic

tnappi

Hi.  I recently downloaded and installed Coppermine, and I really do think it's an amazing tool.  One of my primary image types for what I'm doing is multi-page TIF, and I noticed one omission in the UPLOAD.PHP modifications that I think would be helpful to fix.

The ImageMagick parameters are not being pulled into the CONVERT statement in the current code.  The following is what I did to resolve this:


Original:            exec("convert " . $path_to_image . " " . $path_to_jpg, $convert_output_arr);       // do the conversion to create a jpg
Updated:           exec("convert " . $CONFIG['im_options'] ." " . $path_to_image . " " . $path_to_jpg, $convert_output_arr);       // do the conversion to create a jpg

Also, I added the following switch to the imagemagick options in the config:

-delete 1--1

That command will basically force the convert utility to only pick up the first page as the thumbnail for these multi-page TIF files.

Hope this helps anyone else out that is using TIF's.  I'm planning on applying the TIF conversions to the BATCH upload as well over the next couple weeks (I'm no expert in PHP, so it's going to take me a while!).

-tom

Garibaldi

Hi Tom,

Thanks for fixing this! I'll add a link to your post to the first post in this thread and will include your modification in the next release

Kodak_SLRc

Hi Garibaldi,

I've updated to 1.5.6, then went to make your mod, but it looks like your mod needs to be updated too. Will you be finding time to do this?

Thanks,
Tom F.

Garibaldi

Hi Tom,

I will try and take a look at it soon - though I am unfamiliar with Coppermine 1.5 so I'm not sure about the changes that would be required. What issues have you run into when installing the mod on your 1.5 site?

Kodak_SLRc

Since I really don't know php, I stopped editing the 1.5 files as soon as I could not find the lines of code that one needs to find to install the mod. Two examples I recall, 1) they did away with the URI thing and 2) they changed some array names. (I learned code in the days of BASIC, FORTRAN, and Pascal, so I really don't know the naming conventions/scope rules/etc in any of the modern languages. Thanks to your precise editing instructions I can make the mods with confidence but without exact matches then I'm afraid I'll muck it up.)

My gallery, including the TIFFs uploaded prior to the 1.5 upgrade, is working fine. However I will not be able to upload any TIFFs until this mod is updated.

Sorry I can't be more helpful and thank you very much for sharing your code.

Tom F.

phill104

Yo don't need a mod. Simply go into config>FileSettings and add to "Allowed Document Types" tif/tiff

Do not add it to "Allowed image types" as some users seem to be doing.

It will not be displayed in the same way as above and I have only tested with GD2 but I am sure Imagemagik will support it.
It is a mistake to think you can solve any major problems just with potatoes.

Kodak_SLRc

Hi Phill,

I seem to recall that I tried your suggestion in the past but it didn't offer the functionality that the Garibaldi mod did. To whit, to display a conveniently-sized jpeg while allowing download of large (10+ MB) TIFFs.

In an attempt to refresh my memory, I tried your suggestion. I got this error when I tried to upload a TIFF (it had a .tif extension):
"Error
Only files with the following extensions are accepted: jpg/jpeg/gif/png/asf/asx/mpg/mpeg/wmv/swf/avi/mov/mp3/midi/mid/wma/wav/ogg/tiff/doc/txt/rtf/pdf/xls/pps/ppt/zip/gz/mdb"

I don't understand why tif is not in the list... attached is a screenshot of part of the config.

Thanks,
Tom

phill104

That is indeed very strange as those settings should allow it. Try saving those settings again.

Also please try installing this plugin and see if tiff is included in the list - http://forum.coppermine-gallery.net/index.php/topic,59917.0.html

As for functionality, no, it will not give the same. All you will get is a thumbnail and a full size image. This mod has not yet been implemented on 1.5.x
It is a mistake to think you can solve any major problems just with potatoes.

Kodak_SLRc

Something odd in my installation - the filetypes editor plugin was installed but did not show up at the bottom of the config page. I enabled the plugin manager and found the filetypes editor version was 1.0.2 (I think), leftover from the CPG 1.4.x installation (I think) and not updated when I upgraded to 1.5.x. So I deleted the old and uploaded the new (v2.1) and installed it using the plugins manager. Frustratingly, it still didn't show up at the bottom of the config page. Nonetheless I accessed it directly from the plugins manager using the button located there.

The attached shows what I found: tif was set as image. IIRC, it needed to be that way for the Garibaldi mod to work. I changed tif to document and voila, the tif upload works as you suggested.

But at the end of the day, this is really not what I need. The Garibaldi mod is exactly what I need and I hope his life allows for him to update it some day.

Thanks,
Tom

BM

hello,
can somebody upload the fixed upload.php?

i dont have success in replaceing this code here.

i use coppermine 1.427