RotatePicture

Summary: Easy rotation of attached pictures
Version: 20260317
Prerequisites: PHP7.4+
Status: Experimental
Maintainer: Petko
License: GPL
Users: (view / edit)
Discussion: RotatePicture-Talk

This addon makes it easy to rotate pictures that appear sideways or upside down.

Why

Digital photo cameras and smartphones save the photos in their physical orientation, and only set an "Orientation" EXIF tag to indicate the direction of the gravity. As of 2020, most desktop file managers, picture browsers, and smartphone gallery apps automatically rotate the photos according to their Orientation tag. So an editor may be unaware that the photo is physically in the wrong orientation.

The exception are web browsers which by default do not rotate the pictures according to their EXIF tag. (Except Firefox, and only when the picture is loaded alone, not when it is embedded in a page). The CSS setting image-orientation: from-image; is not widely supported, and the thumbnail galleries (Mini, ThumbList) may create a thumbnail in the wrong orientation.

The solution presented here allows to manually rotate a picture by clicking on a link (rotate left, right or upside down).

When a picture is rotated, the original file is not lost, it is renamed and appears as a deleted file in the uploads directory and on the Attach tab.

Installation

Place rotatepicture.phpΔ in your cookbook/ directory. Add to config.php:

include_once("$FarmD/cookbook/rotatepicture.php");

Usage

In a wiki page, add this directive:

(:rotatelist:)

It will display all pictures and below every one there will be 5 links, to rotate the picture left, right or upside down, and to flip (mirror) the picture horizontally or vertically.

Click on a link to rotate or flip the picture.

You can include this directive in Site.UploadQuickReference, that way it will appear when you follow the "Attach" link.

Configuration

The variable $RotatePicture['ListFmt'] contains the wikitext template that will be used to display the list of pictures, with %1$s to be replaced with the file name, %2$s the url-encoded file name (for use in an URL).

Notes

  • Depending on your server, browser, and proxy configuration, after rotation, the browser may show the old picture from cache. Hold down the Shift key and press the circular arrow to reload the page, then release the Shift key. This should clear the cache.
  • Only pictures attached to a wiki page, in the corresponding upload directory, are supported, and only if the current user has "upload" permissions. There are no plans to change this.
  • It may not work well together with MiniEdit (YMMV).
  • Photos in JPEG format are saved with the default quality (75). The rotation is lossy, it has a small reduction of the sharpness with every rotation.
  • Graphics in GIF or PNG formats are saved without a quality loss.
  • Animated pictures (GIF or WEBP) are not supported and should not be rotated, the risk is for only the initial frame to remain.

To do / some day / maybe

If there is interest / funding:

  • Lossless rotation with jpegtran or exiftran if available on the server.
  • Configurable JPEG quality.

Change log / Release notes

  • 20260317 Add cache-busting code for the thumbnail list.
  • 20260316 Add WebP picture format. Improve handling of filenames with spaces. Scale down the picture to 100px height. Add flip horizontal and vertical. Make list compatible with Filterable.
  • 20200116 First release, ready to be tested.

See also

Cookbook /
Mini  Simple, lightweight, un-bloated gallery with thumbnail generator
ThumbList  A thumbnail picture gallery for PmWiki

If you use Mini, see https://tl.5ko.fr/M/Orientation for a function to automatically rotate most of the pictures.

Contributors

Written and maintained by Petko, partly based on Mini.

Comments

See discussion at RotatePicture-Talk

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.