UploadPicCompression

Summary: Compress uploaded image files
Version: 7 March 2005
Prerequisites:
Status:
Maintainer: PatrickOgay
Categories: Images, Administration

Goal

Pictures (jpg, png, gif) should/can be compressed on the fly while uploading (Attach:)
So you can upload a picture from Digicam (if you have a fast internet connection:-)

Solution

I found a nice working PHP/GD Script on Yuriy Horobey's website http://horobey.com/demos/imgresize/v5/article/article01.html

(see also Cookbook/ImagesAutoResizing, which might be very useful for a gallery)

The script is a pure php-solution and easy adaptable in the pmwiki environment.
The uploadform gets two addtional fields width/heigh.

  • if width and high are blank, no resize
  • "*" or blank on one field, proportional resize (very nice)
  • some plausi on size
  • resize for jpg, png and gif

Changement in config.php

 
# another Entrypoint instead of upload.php:HandlePostUpload */
SDV($HandleActions['postupload'], 'HandlePostUploadImpr');
# Entrypoint and GD-Picture Compression  
require("local/resize_image.php");
# Modified Form (from upload.php) for Attach: files.xyz
SDV($PageUploadFmt,array("
  <div id='wikiupload'>
  <h2 class='wikiaction'>$[Attachments for] \$FullName</h2>
  <h3>\$UploadResult</h3>
  <form enctype='multipart/form-data' action='\$PageUrl' method='post'>
  <input type='hidden' name='n' value='\$FullName' />
  <input type='hidden' name='action' value='postupload' />
  <table border='0'>
    <tr><td align='right'>$[File to upload:]</td><td><input
      name='uploadfile' type='file' /></td></tr>
    <tr><td align='right'>opt. for Pics width/height</td><td><input
      name='w' type='text' size='3' /><input
      name='h' type='text' size='3' /> Resize in Pixel, *=calculates automatically 
    </td></tr>
    <tr><td align='right'>$[Name attachment as:]</td>
      <td><input type='text' name='upname' value='\$UploadName' />
        <input type='submit' value=' $[Upload] ' /><br />
        </td></tr></table></form></div>",
  'wiki:$[PmWiki.UploadQuickReference]'));


resize_image.phpΔ

Notes and Comments

  • the script is easy adaptable in pmwiki

Open Issue March 07 2005

  • the function is under development and not quite finished, but it works already.
  • Pics are always stored as JPG, gif probably can not be stored as gif (depends on GD-Library)
  • So the name of the ending can be different to Attach: file.ending
  • Test: http://www.ddy.ch/pm/schulung/pm.wiki/Main/WikiSandbox (At the moment it works unfortunatly only with admin, so you can't make an upload.
  • I hope to finish the recipe as soon as possible

Contributors

PatrickOgay - prototype March 7, 2005

User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.