TIP 611: Add subcommands to the "photo image" command to rotate and reflect an image

EuroTcl/OpenACS 11 - 12 JULY 2024, VIENNA
Author:         Arjen Markus <[email protected]>, Richard Suchenwirth <[email protected]>
State:          Draft
Type:           Project
Vote:           Pending
Created:        2-Sep-2021
Tcl-Version:    9.1
Implementation-URL: https://wiki.tcl-lang.org/page/rphoto


The purpose of this TIP is to enable scripts to rotate a photo image over +90 or -90 degrees or reflect it in the horizontal or vertical axis. The image is rotated or reflected in-place.


Various commands, such as subsampling, are already available to manipulate image data. A simple manipulation that is missing from the current set of manipulations is rotation over 90 degrees in clockwise or counter-clockwise direction. Code to so has been available on the Wiki since 2010.

Reflection is possible by using negative increments for subsampling an image. This is part of the copy subcommand and creates a new image.

While it would be possible to implement rotation as an option of the copy subcommand, this presents a delicate problem: how would this interact with the other options? Should these options be handled in the order in which they are specified or should there be some hierarchy?

To avoid ambiguities and effects that are difficult to explain, this TIP proposes to introduce separate subcommands for the two isometric transformations.


This TIP implements two new subcommands for photo images, rotate and reflect, that have the effect of rotating the image by 90 degrees in a clockwise or counter-clockwise direction or reflect it in the central horizontal or vertical axis.

The subcommands are limited to photo images, as that is the most likely format for which such a facility is useful.

The syntax is:

$img rotate -90/90

where -90 means a clockwise rotation and 90 a counter-clockwise rotation. (Note: the angle should for the moment be a multiple of 90 degrees.)

For reflection the syntax is:

$img reflect h(orizontal)/v(ertical)

where "h" (or any abbreviation of "horizontal") means reflection in the central horizontal axis and "v" (or any abbrebation of "vertical") means refletion in the central vertical axis.

A reference implementation for rotating an image in place exists as a standalone extension -- https://wiki.tcl-lang.org/page/rphoto.

Moreover, Christian Werner has proposed an implementation for this TIP for both rotation and reflection, see https://core.tcl-lang.org/tk/tktview/2058b607301bca07ed3bea2114579a01a42a6756

The patch accepts angles other than multiples of 90 degrees and then determines the closest multiple. An alternative could be to issue an error message.


This document has been placed in the public domain.