Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Keeping quality and EXIF data in uploaded jpg files?

KristianBKristianB
edited April 2015 in Vanilla 2.0 - 2.8

We run a discussion forum with photos from nature as its central subject. With great help from the experts in this community =) we recently made a successful transition from Vanilla 1 to Vanilla 2. But the image plugin ImageUpload has a most unfortunate property: The uploaded files are changed from the originals which means that the images are recompressed (smaller files) during which process all EXIF data are lost and the image quality is significantly impaired. Both is most unfortunate for a forum with photos as the main subject. Is there any way to change the code in the ImageUpload plugin to simply copy the original image file?

Comments

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited April 2015

    Just guessing, but you could check your config.php for these and make the values larger like below..

    $Configuration['Plugins']['UploadImage']['MaxHeight']='2000';

    $Configuration['Plugins']['UploadImage']['MaxWidth']='2000';

    $Configuration['Garden']['UploadImage']['Quality']='100';

  • KristianBKristianB
    edited April 2015

    Thanks, @vrijvlinder, I had already done the following. In the file class.imageupload.plugin.php there are the following lines:

    $Sender->AddDefinition('ImageUpload_MaxFileSize', C('Plugins.UploadImage.MaxFileSize', '2mb'));

    and:

    $Props = $UploadImage->SaveImageAs($TmpImage,$TargetImage,C('Plugins.UploadImage.MaxHeight',''),C('Plugins.UploadImage.MaxWidth',1024));

    The first one is the original one in the plugin - as I thought that a file size of max 2 MB would be more than sufficient.

    In the second one I have changed the default value of 650 to 1024. That worked. Now, images below a width of 1024px are left unchanged whereas broader images are resized to 1024px. However, even if the images are 1024px or below, the file size is reduced - causing a loss of details in the photos.

    In config.php I find the following:

    $Configuration['Garden']['Picture']['MaxHeight'] = 1000;
    $Configuration['Garden']['Picture']['MaxWidth'] = 600;

    The values there apparently are overruled by the value (1024) that I already changed in the plugin, this part works.

    However, I cannot find any definition as to Image or Upload quality in the config.php.

    And furthermore, I am very reluctant as to changing anything in config.php. During my attempts to configure our forum I last week made a few minor changes in the config.php - which apparently caused the database to crash so that I had do reset everything and continue my work with a blank forum. (If I have to make changes in config.php I need someone to explain detailed step by step how to do it).

    Anyway, it is unclear to me where exactly the file size/image quality is changed during upload when using the ImageUpload plugin.

  • config should not cause the database to crash unless the database is already unstable or in need of repair.

    grep is your friend.

  • Thanks again. I just thought that it would be absolutely uncomplicated if the upload plugin simply transferred the original image file as is without making any changes. But perhaps this isn't possible?

    Well, my database was only a few says old with perhaps 50 (test) comments so it was no diaster to reset it. I would hate if it happened today! The problem may have been that I (as far as I recall) downloaded the config.php, renamed it, made a few changes, and then uploaded the renamed version. Next step was that I deleted the config.php and then renamed the modified file back to be called config.php. Apparently, this file wasn't accepted by the program.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited April 2015

    The config.php is susceptible if you use a regular text editor to edit it because unwanted characters can be inserted. Also if you miss a ; or a , or '' . Use FTP to edit files and a good text editor that recognizes codes.

    That is where the changes you made to the plugin get saved. So changing the plugin is the same as adding the configuration or changing the values.

    This configuration is what controls the quality of the image, the default is 64 percent.

    $Configuration['Garden']['UploadImage']['Quality']='100';

  • Just to be absolutely shure: Do you say that the following procedure 1) Download config.php 2) modify with my html-editor or eg. PHP editor by just adding the line

    $Configuration['Garden']['UploadImage']['Quality']='100';

    and then 3) upload again (= overwrite) - should be safe and prevent the program from resizing the jpg images during upload?

    But what about the EXIF data, will they also survive the upload process?

    (Sorry for being so dull-witted).

  • I have now searched through the php files of Vanilla and found the following:

    ..\vanilla\library\core\class.uploadimage.php

    where I found the line:

      $Crop = FALSE; $OutputType = ''; $ImageQuality = C('Garden.UploadImage.Quality', 75);
    

    I changed this to:

      $Crop = FALSE; $OutputType = ''; $ImageQuality = C('Garden.UploadImage.Quality', 100);
    

    and now the uploaded image retain its dimensions and its size - well, almost.

    I uploaded a 1024px wide jpg in full resolution. File size 448 kb. After upload file size was reduced to 418 kb. I expect that this will cause no loss of details og sharpness when viewed in the forum.

    However, all EXIF data were lost!

    Isn't it possible somewhere to change the code so that the original file is uploadet unchanged?

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Just to be absolutely shure:

    Yes,Try Sublime 2 text editor it is free to try if in doubt.

    should be safe and prevent the program from resizing the jpg images during upload?

    You need to understand the difference between size/dimensions and weight/how heavy the file is in bytes and Quality/resolution in pixels.

    All of those need to be set up to the ideal values.

    But what about the EXIF data

    As far as I know FileUpload and Uploader do not strip any data . The images that contain any data will always contain it because it is part of the image if it was saved with the exif data. . Try this out here:

    http://exifdata.com

  • LincLinc Detroit Admin

    Beware that disabling image processing could have other side effects, like no thumbnails. My suggestion that follows also requires modifying core files, which, on balance, is generally a bad idea because it makes it harder to update (which is extremely important to do regularly). If you don't mind re-doing this every couple months, carry on. Also, I haven't tested this, it's simply my best flyby guess of the easiest way to stop image processing.

    Go to library/core/class.uploadimage.php and find this:

       public static function ImageSize($Path, $Filename = FALSE) {
          if (!$Filename)
             $Filename = $Path;
    
          if (in_array(strtolower(pathinfo($Filename, PATHINFO_EXTENSION)), array('gif', 'jpg', 'jpeg', 'png'))) {
             $ImageSize = @getimagesize($Path);
             if (!is_array($ImageSize) || !in_array($ImageSize[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG)))
                return array(0, 0, FALSE);
             return $ImageSize;
          }
          return array(0, 0, FALSE);
       }
    

    and replace it with:

       public static function ImageSize($Path, $Filename = FALSE) {
          return array(0, 0, FALSE);
       }
    

    Let us know if that works.

  • Thank you both!

    Yes, @vrijvlinder , I am aware of the difference - I just don't know the proper English words for it!

    @Linc: The effect of your suggested code is that an image of 1024x855 px and 268 kb after upload is 1024x855 px and 474 kb. But the EXIF data are lost during the process!

    I have also been using the Uploader plugin. It keeps the EXIF but I prefer to have the image placed in the text and not as a thumbnail underneath!

  • I have choesen to solve the problem like this:

    In the ..\vanilla\library\core\class.uploadimage.php

    I simply changed:

      // Never process icons
      if ($Type == 17) {
         $Process = FALSE;
      }
    

    to:

      // Never process jpegs
      if ($Type == 2) {
         $Process = FALSE;
      }
    

    Now the original file is uploadet without any changes whatsoever.

    Thanks for your help - and patience!

  • EXIF is just there so portable devices don't have to do any heavy lifting when taking photos, and assume other devices can read EXIF.

    You could put the code to re-orient the picture.

    grep is your friend.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited April 2015

    Ok, that seems to work but I don't like removing code that is useful so I did this instead. This seems to help when images are very big in dimensions and the thumbnail was not created, now it is . I think this should be in the core...

    // Never process icons
      if ($Type == 17) {
         $Process = FALSE;
    }
    // Never process jpegs
     elseif ($Type == 2) {
         $Process = FALSE;
      }  
    
  • Yes, @vrijvlinder, I am sure that you are right - I just wasn't sure whether it would work if both expressions were present at the same time. Furthermore, our forum is only open for a limited number of members with the purpose of presenting - and commenting - photos for each other. I, therefore, believe that the functions and mode of action of the Vanilla forum will not be compromised by these modifications of core files. Had it been a general discussion forum with hundreds of users it could definitely be a potential problem.

    I will, however, change the file according to your recommendations.

    Once again, thanks to all of you for all your help and valuable advise!

    (You may visit us at http://naturnettet.dk)

Sign In or Register to comment.