horizontal stack of polaroids?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
pooco

Re: horizontal stack of polaroids?

Post by pooco »

modification of above, this one grabs the most recent 5 jpgs from a file tree of any depth

you had a small bug in your script-- tmpfile needs to be set at top and added to end of first convert line

if i have time i'll do what i said in the previous message soon.

Code: Select all

#!/bin/sh

numberofimages=5 # number of recent images to grab
center=0     # current center location for the next image
offset=100      # distance to the next images center.
tmpfile=/tmp/polaroids.png # temporary file
outfile=result.png # finished file
background=transparent   # background canvas color

# Grab the newest 5 jpgs from your file tree
files=`ls -altr \`find . -name '*.jpg' -type f -print\` | grep -v $outfile | tai
l -$numberofimages | awk '{ print $8 }'`;

echo "Processing images: " $files;

for image in $files
do
   # read, thumbnail, polaroid image to a temp file.
   # I used super-sampled polariod to make the result better
   # This could have been done in a previous step to this loop
   convert -size 500x500 "$image" -thumbnail 240x240 \
       -set caption '%t' -bordercolor snow -background black \
       -pointsize 12  -density 96x96  +polaroid  -resize 50% \
       $tmpfile

   # Now gather image size, half it, and determine its virtual canvas
   # location so as to place it's center at the current position.
   xpos=`convert "$tmpfile" -format "%[fx: $center - w/2 ]" info:`
   ypos=`convert "$tmpfile" -format "%[fx: - h/2 ]" info:`

   # $ypos is always negative
   # but $xpos may be positive, in which case it needs to have a '+' sign
   xpos=`echo "+$xpos" | sed 's/+-/-/'`

   # Output the image into the pipeline for placement on canvas
   # at the position (for top-left corner) calculated
   convert -page $xpos$ypos "$tmpfile" MIFF:-

   # increment position for next image  (lets use IM for the math ;-)
   center=`convert xc: -format "%[fx: $center + $offset ]" info:`
done |
  # Now we read the pipeline of the images output from the above loop
  # and create the canvas.  Repage the virtual canvas, add some extra
  # border space and output it.
  convert -background "$background"  MIFF:- \
         -layers merge +repage \
         -bordercolor "$background" -border 5x5 $outfile
pooco

Re: horizontal stack of polaroids?

Post by pooco »

also, here's how to do the one-liner

Code: Select all

montage -gravity center null: `ls -altr \`find . -name '*.jpg' -type f -print\` | tail -6 | awk '{ print $8 }'` null: -thumbnail 128x128 -sharpen 10 -set caption '%t' -bordercolor snow -background grey20 +polaroid -set label '' -background Transparent -geometry '1x1-40+0<' -tile x1 miff:- | convert - -trim +repage recent.png
annotated

Code: Select all

montage -gravity center null: `ls -altr \`find . -name '*.jpg' -type f -print\` | tail -6 | awk '{ print $8 }'` null: -thumbnail 128x128 -sharpen 10 -set caption '%t' -bordercolor snow -background grey20 +polaroid -set label '' -background Transparent -geometry '1x1-40+0<' -tile x1 miff:- | convert - -pointsize 10 -rotate -90 -gravity north -fill "#868686" -annotate 0 "Newest images\nas of `date '+%b %d'`" -rotate 90 -trim +repage recent.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: horizontal stack of polaroids?

Post by anthony »

Montage would not let you give a random 'jitter' to the photo locations. But of course my script has complete place ment control. you could do a circle of photos if you want!!!!

As for a montage one liner. In a shell script (UNIX), which as the script I gave works for you, you must be using, environment, you can use 'backquotes' to insert the results of the quoted command at that location. Better still the BASH method of $(...) is better
as you can then nest commands as argument input of another command, of another command, etc... the backquote method only allows one such nesting.

For example..

montage -size 200x200 null: `find . -name '*.jpg' | tail -5` null: -tile x1 ......

will replace the `...` part with the output of the command given. as long as that output has no spaced in the filenames, or other weird characters (that is you control the file names, which I assume is the case), then you will have no problem with it.

Hey Presto Changeo... A one line UNIX command. A long one, but still one line.

PS: bash scripts can be one line too EG:
for i in `find . -name '*.jpg' | tail -5`; do convert ....; done | convert ....
the trick is adding semi-colons in the right place. However the line will get VERY VERY VERY long, making it not worth the effort.

You also have shell functions. You can predefine routines, to make it easier to
call the pre-prepared functions from the command line. However her you are in shell scripting, and getting far away from IM problems :-)

Enough Said...
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply