Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

ImagesAutoResizing

Summary: Creates a small image on the page, with a link to a larger image
Version: 2.0
Status: Stable
Prerequisites: pmwiki-2.0.beta10
Maintainer: PRZ
Categories: Images
Votes:

Goal

When loading an image, create a smaller image on the page, with a link to a larger image.

Solution

The Minimage module : Please report any problem in the discussion paragraph below or by mail.

Add the following line to local/config.php

    include_once('cookbook/minimage.php');

Notes and comments

  • This recipe was last tested on PmWiki version: 2.1 beta30
  • Needs the GD library (V 2.03+) to be installed on the server
  • php code size: 16 ko, around 50% of that code being parsed every time, the remaining only when uploading image.

Usage

Set Img:image.ext anywhere in your page As example :

 Img:myimage.jpg

If default dimensions are not ok for you, you can impose the dimensions by setting Img:small_size*plain_size*image.ext. As example:

 Img:150*800*otherimage.gif

Note: the use of '.' as separator for size characterization is no longer accepted. You should remove it to still have working links. - Sorry for that, see the discussion for explanation -

Image type is limited to jpeg, gif and png. When clicking on the Img call, a screen will open to invite you to upload your image and create or modify IPTC tags.

After validating the input, the images are resized and stored on the harddrive.

To force resizing of an existing image, use a leading star (*), which should be removed later:

 Img:*220*1024*myimage.jpg
Tip: to resize an image, edit the page, add the dimensions to be forced, make a preview, which will drive to image recalculation (not shown because the image is still in the cache), cancel the edit, and force the reload of image with [Shift] + reload button. That way, you have nothing to remove...

If the small image is of same size as the plain image, there will be no link to the plain image. So by example :

 Img:350*350*AnImage.jpg 

will simply display the image with a dimension of 350 pixels.

There is no size limitation (but your server probably have limitations), but wrong files will be automatically deleted, and too large source images will be resized.

This script do not resize images lower than (1.15 * required size) -to limit quality loss when image is slightly larger than required. This coefficient can be modified (parameter $OverSize).

Site example :

You can also load images by FTP. They will be resized at first display. In that case, the IPTC tags will be the defaults for caption and special instructions, and the copyright owner will be the first one to display the images... (read on the author cookie). For files loaded via FTP, image extension shall be in lower case.

  • Small image is stored as image.s.ext (displayed on page)
  • Plain image is stored as image.p.ext (small image link to this one)
  • Archive image is stored as image.ext (not displayed)

If plain image is of same size as the archive image, the archive will be automatically deleted.
This archive image can be simply displayed with an Attach:image.ext.
It have a maximum size and will be resized if exceeding this maximum. If you want to remove the archive files, set the maximum archive size identical to the plain displaying size.

Configuration

On PmWiki2 only. Need to have the GD library installed in a version above 2.03 (to allow image resampling). This library is part of the PHP distribution but not always installed, because it is delicate to install, and also use significant server resources. If resizing not possible, a message will be displayed.

Needs to have PmWiki uploads enabled. The password is the upload password. Storage directory is the same as for upload.

   #$WriteGif=FALSE; // Force inactivation of Gif writing  
   #                 (default TRUE, but check function existence) 
   #$DispIPTC=FALSE; // Stop interactive IPTC input (default TRUE)  
   $img_smallsize = value; //Larger size of displayed image,default 256 
   $img_plainsize = value; //Larger size of linked image, default 768 
   $img_archsize = value; //Max size of archive on drive, default 1280 
   ## Setting archive size equal to linked size remove archive files 
   #$OverSize = value;//extra size which do not allow resizing,default 1.15 
   ## Default IPTC tags (jpeg images only) 
   $def_iptc_caption = 'text';  
   # if no caption tag exist, default 'Image collected on a PmWiki' 
   $def_iptc_copyright = 'text';  
   # if no copyright tag exists and no Author defined, default empty 
   $def_iptc_special = 'text';  
   # *appended* to existing special instruction tag, default empty. 
   # Maybe used to defined a site licence (cc or artistic or whatever).  

When interactive IPTC tags are unactivated, parametered values are used, and the Author (as defined in the cookie) is set as copyright owner, if no default author set. To unactivate author setting, set a '-' or any char as default author.

Translations

The strings to be translated are defined in the PmWiki.XLPageCookbookTemplate page, which is used to create any local XLPageCookbook page.
Done :

Explanation and user documentation :

See also this page translated :

Limitations

  1. I have not been able to rewrite IPTC tags on an image which already have these tags. So in that case, tags are left 'as is'.
    I have no idea of what is wrong, so for people who are able to understand these sort of things, here are links to the php source code for function iptcembed() :
    - www.koders.com
    - lxr.php.net
    If someone knowledgeable can have a look...
  2. Even if the creation of gif images is said to work on your server, this may be not the case. On my webhost, that drive to an internal server error.
    To force inactivation of gif writing, set $WriteGif=FALSE;
  3. If gif creation is not allowed the script create jpeg images with extension '.gif' (say, the internal format -jpeg- is not the one said by the extension -gif-).
    This is not quite neat but is handled properly on most browsers.
  4. This PHP add-on creates images. On some hosts, you may not be able to remove by FTP these PHP created files. See the cookbook PHP Files Management to solve the problem.

License

GPL

History

  • 27 nov. 2004 V0.1 - 1rst issue - This is my very first php script, and what a fight! Also, that was not the easiest to begin with...
  • 28 nov. 2004 V0.2 - Solved problem with pages containing accented letters.
  • 29 nov. 2004 V0.3 - Solved problem with .jpeg extension. Allow uppercase file extension (but stored on drive as lowercase)
  • 1 dec. 2004 V0.4 - Cosmetic - Added parameter $WriteGif to block gif writing. Added $DispIPTC to allow/block interactive input of IPTC parameters.
  • 26 dec. 2004 V0.5 - Corrected to work with PmWiki 2.0Beta10 and over
  • 8 jan. 2005 V1.0 - Working thumb reload - parameter $OverSize
  • 16 jan. 2005 Added user documentation page in zip file
  • 16 jan. 2005 V1.1 - removed glob() function, not existing on all servers
  • 30 jan. 2005 V1.2 - added possibility to force dimensions
  • 31 jan. 2005 V1.3 - serious code cleaning, added upload log in file (All)RecentUploads.
  • 04 feb. 2005 V1.4 - allow mixed lower/uppercase in file extension.
  • 13 feb. 2005 V1.5 - no link to image which have the same dimension - Can now force resizing of an existing image.
  • 13 feb. 2005 V1.6 - bug release on one parameter upload
  • 24 apr. 2005 V1.7 - display IPTC parameters with plain image
  • 16 may 2005 V1.8 - correction htmlentities on displayed text (accented chars)
  • 31 oct 2005 V1.9 - now display in IE images with names having accented chars - $EnableDirectDownloads=0; is now valid (thanks to Bill Wraith).
  • 1 Nov 2005 V2.0 - now display upload thumb in indirect download
  • 10 Dec 2006 V2.1 - can upload to other directory, remove actions in screens

Contributor

PRZ

Categories: Images

Discussion

THANKS! This is a nice feature I've really been waiting for! :-)
Just one question: If the user gave the wrong dimensions at uploadtime: Can he change the sizes later? If not: Is it possible to implement such a feature? - Gerhard

Done on V1.5 PRZ

Since installing v1.3 I get for half of my photo's "invalid file extension". what has happened? (I'm using Mac OSX for server and maintenance. the file extension is .jpg) Han

It seems that a filename with ONLY numbers (like 123.jpg) is no longer accepted. Renaming part of my uploaded photos has solved the problem. Thanks for the quick reaction, Han

Ah, yes, the number is interpreted as the required sized of an empty name. It have been solved on V1.5 by requiring to use only '*' character instead of '.' as separator for size.
Unfortunately, that will broke links of people who have used it for size characterisation. PRZ


Made some changes to the code for a change-proposal anyone may figure out for him/herself what can be of use from it...
Some extra's incorporate limitations to print or publish actions (like when someone is printing, nobody requires deeplinking anyway, however also these links are used to store pages off-line, so in some cases they might be useful.)
I removed the links in there because I used offline-website grabbers to grab the publish content. (or use scripts to create PDF files) and i don't need stuff that won't work out in that matter. Also, I need to patch the script once more to remove WikiWord pages that do not exists yet in that concept. (links that involve "&action=edit")

Regards,

VincentVoois

This is a too special use, so i will not implement anything in the base code. Some suggestions:
To get the action of the URL (or of a post) do $action = @$_REQUEST['action']; (the @ stops the errors)
You can try to add after the line:

  $flpthPlain = str_replace('.s.','.p.',$flpthSmall);

something like:

  if (@$_REQUEST['action']=='publish') $flpthPlain = '';

Which will make like if the plain file don't exist and stop the link (in last version). - untested -
PRZ


sounds great but everything goes along fine until I click the upload button and i then get:
Call to undefined function imagecreatefromjpeg() in $pmwiki/cookbook/minimage.php on line 283

This happens with any image type, the only difference being that imagecreatefromjpg will change to imagecreatefromgif or imagecreatefrompng etc depending on which type of image i try to upload.

all file locations and permissions are correct.

any ideas how I might get past this stumbling block?

thx

It probably means that the GD image library (which should be over 2.03) is not properly installed in the PHP installation. Without that library, this recipe and all others galleries cannot work.


The text file in the zip has incorrectly formated the include statment. Should be:

 include_once('cookbook/minimage.php');

Something, minor. BTW, great script, esp for first time! A couple of enhancements that would be nice:

  1. Show the caption under the thumbnail
    1. (24AUG05 update) A work around is to use a float or frame and seperate the image string from the caption with an upright " | " (e.g. %rfloat%Img:Image.ext | caption)
  2. Option for floating the image PB (25Jul05)
    1. (24AUG05 update) Again using the frame floats now available since beta52 and improved in beta55 (e.g. %rframe%Img:Image.ext)

It would be nice to have something like: which provide thumbnails of all the uploaded images of a group.


Would it be possible to set with "$img_smallsize" the '*width*' of displayed image, instead of the larger size of the images? This would make it possible to display the thumbs in a nice evenly spaced collumn.
Thanks, Han, 2 okt 12.43 CEST


I have a bug with this recipe : form submiting did nothing but bring back my PmWiki home. I had to change minimage.php line 249 from:

<form enctype='multipart/form-data' action='\$ScriptUrl' method='post'>

to

<form enctype='multipart/form-data' action='\$PageUrl' method='post'>

KzarDotNet February 17, 2006, at 03:48 PM


I wish to upload pictures into folder defined in my localmap as Pics.
While Attach:Pics:/test.jpg uploads there, Img:Pics:/test.jpg uploads the file into Uploads/currentgroup folder as a filename Picstest.jpg
Any solution ? Jiri October 19, 2006, at 05:40 AM


Hi I am constantly getting ErrNoResize message after uploading an gif or jpg and setting the Img: markup to the specific file. The attachment itself gets uploaded and can be attached to the page normally. I tried deactivating gif creation set $WriteGif=FALSE; in the minimage script, this didnt help. Any suggestions? Thanks Boris
Most probably the GD library is not installed on your server, so it is not possible to resize images. PRZ March 16, 2007, at 07:00 PM


Seems to work fine, but I do not get an upload form with the image caption/copyright etc as seen above. If I put a fake link in like img:addfile.gif this comes up as a link to upload file and then shows the caption and copyright etc, but does not allow me to change the name of the file from addfile.gif to realname.gif. bouton? Nov 15, 2006


Doesn't work with PmWiki 2.1.27. After uploading a file, it gives Attach:Img:test2.jpg on page render. Bianka? Feb 27, 2007
Never heard of such problem. Works ok for me on recent pmwiki version (2.2.0 beta 38). Some details about your configuration ? PRZ March 16, 2007, at 07:00 PM


In order to get alpha channels working on pngs and maybe even gifs. find $newimage = imagecreatetruecolor($newwidth, $newheight); after add imagealphablending($newimage, false); and find $typeout=$type; after add imagesavealpha($newimage, true); now when thumbs are made of png's with alpha channels there saved. Scotepi June 17, 2007


Can I add any alternate text for small image?


There appears to be a small error in minimage.php. The expression:

	if (@$_POST["Cancel"]) {
		ImgExit($pagename);
	}

should be:

	if (@$_POST["canc"]) {
		ImgExit($pagename);
	}

to match the <input type='submit' name='canc' value=' Cancel ' /> statement.

Edit - History - Print - Recent Changes - Search
Page last modified on January 12, 2008, at 01:56 PM