RotatePicture
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 3 links, to rotate the picture left, right or upside down.
You can include this directive in Site.UploadQuickReference, that way it will appear when you follow the "Attach" link.
Click on a link to rotate the picture.
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.
If you already use Mini, you can do something like this:
$RotatePicture['ListFmt'] = ">>frame display=inline-block<<\nMini:%1\$s\"%1\$s\" | " . ' [-rotate-] [[{$FullName}?upname=%1$s&action=rotatepic°=90"Rotate Left"|↶]] ' . ' [[{$FullName}?upname=%1$s&action=rotatepic°=-90"Rotate Right"|↷]] ' . ' [[{$FullName}?upname=%1$s&action=rotatepic°=180"Rotate Upside Down"|↺]] '."\n>><<\n"; include_once("$FarmD/cookbook/rotatepicture.php"); if($action == 'upload') MiniHeaderFmt(); # for UltraLightbox
It will show the pictures as thumbnails, in frames with the links to rotate them.
Notes
- It may not work well together with MiniEdit (YMMV).
- It may not work well, or at all, with file names with spaces or special characters.
- 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.
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
- 20200116 First release, ready to be tested.
See also
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.