Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Tk and GD to custom rotate, resize and crop jpg images

by Discipulus (Canon)
on Mar 15, 2021 at 15:57 UTC ( [id://11129680]=CUFP: print w/replies, xml ) Need Help??

Hello folks!

Tk and GD again. Imagine to have a lot of pictures of the same subject, let say historical Kawasaki motorcycles, but where this subject is off center, sometimes bigger sometimes smaller, other times the picture is rotated and you want to have them with the subject of the same size, always horizontal and all pictures centered. Dreadful hours of photo editing or.. tk-jepg-custom-rotator! :)

DESCRIPTION

Jpg custom rotation, resize and crop. The program loads a list of jpg images and let you to apply one or more of the following modification:

  • A custom rotation setting two points (P1 and P2) on a preview image using mouse buttons. The center of the line P1-P2 will be used as center of the rotation. The rotation will be always applied to make P2 on the right side of the resulting image.
  • A custom resizing of the image specifying a fixed size for the line P1-P2 in the destination image. The resulting image will be streatched or reduced accordingly.
  • A custom cropping of the image specifying a target resolution for the destination image. The image will be cropped around the center.

SYNOPSIS

Command line options:

   --forcelinesize N
       makes the line to be exactly N pixel in the destination photo
       stretching or enlarging the file accordingly. This switch forces 
       'enable resizing' in the control panel to a true value.
   
   --cropwidth N
       fix the width of the destiantion image. This option forces 
       'enable cropping' in the control panel to a true value. Both 
       cropwidth and cropheight must be specified
   
   --cropheight N
       fix the height of the destiantion image
       
   --devdebug
       enable more verbose output and the creation of debug images at 
       each step of the processing

KEY BINDINGS

Preview Window:

    Button-1    (left click)    set point1
    Button-3    (right click)   set point2
    space                       modify the photo and loads the next one
    Button-2    (middle click)  modify the photo and loads the next one
    p                           reload the previous photo
    n                           skip the current photo and load the next one

HOW IT WORKS

The program consists of a control panel and a preview area. The informative output is written to the console used to launch the program. In the control panel you build the list of images to process, add or remove image transformations, control the name used to save images and control the debug level and can access this documentation.

Choose P1 and P2

A preview image is created from the original image using the specified ratio and you can left click with the mouse on it to set P1. You che click several times to set P1 to a ne position.

Right clickin on the previe image sets P2, but only if P1 is already set. At this point a line is drawn in red on the preview image with an arrow on P2 and a little yellow circle to show the center of the line.

Once points are set, hitting Button-2 (the midlle mouse button) or spacebar all enabled transformations are applied to the original image and the result is saved with the name composed using the logic the user choosen in the control panel.

Rotation

The rotation of the image is made firstly cropping the original image at the center between P1 and P2. The original size is used and a black background is used. This temporary images is then rotated to make the P1-P2 line to be horizontal and P2 on the right side.

Resize

If enabled and a fixed size is specified for the P1-P2 line then the image is reduced or enlarged accordingly.

Cropping

The crop is made around the center between P1 and P2 using width and height specified in the control panel.

DEBUG

Beside normal verbose output activated by --debug command line switch or by the dedicated check in the GUI, there is also a --devdebug switch that add more verbose output but also writes an image at each stage of the prcessing with points and lines in the relevant positions. These images will have fixed names and will be ovewritten when a new jpeg is processed. While --devdebug is active the preview window has another binding: CRTL + d which dumps on the screen the relevant part of the object.

AUTHOR

This program was done by LorenzoTa and the main repository can be found at gitlab

The main support site for this software is perlmonks.org where i can be reached as Discipulus

LICENSE

This software is povided as is and it is licensed under the same terms of Perl itself.

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://11129680]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-19 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found