"clone"/extend right most column of pixels to fit available space

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
SteveTheTechie
Posts: 2
Joined: 2015-01-25T19:56:05-07:00
Authentication code: 6789

"clone"/extend right most column of pixels to fit available space

Post by SteveTheTechie »

How to use PerlMagic to duplicate/extent the right most column of pixels from an image to fit a given width.

See the masthead image at the top of http://brian.toastmastersclubs.org, for example. I want to be able to dynamically vary the width of this image to adapt it to varying user screen widths by duplicating the right most column of pixels in the image to fill the empty space on the left and right sides of the image.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: "clone"/extend right most column of pixels to fit available space

Post by snibgo »

There is probably a better way, but this works. Windows BAT syntax. Sorry, I don't know Perl.

Suppose you want the banner to become 1234 pixels wide.

Code: Select all

convert ^
  club1.jpg ^
  ( +clone ^
    -flop -crop 1x+0+0 +repage ^
    -scale 123400%%x100%% ^
  ) ^
  +swap ^
  -gravity West ^
  -composite ^
  out.png
This makes a copy, mirror-images it left-to-right, and takes the first column. So now we have just the last column of the original image, one pixel wide. We scale it 123400% horizontally and 100% vertically. This stretches it out to 1234 pixels wide. We swap these, and place the original over the stretched image, left-justifying it.

If you can, you should start from a source that isn't a jpeg.
snibgo's IM pages: im.snibgo.com
SteveTheTechie
Posts: 2
Joined: 2015-01-25T19:56:05-07:00
Authentication code: 6789

Re: "clone"/extend right most column of pixels to fit available space

Post by SteveTheTechie »

Thank you very much!!! I will give this a shot.
Post Reply