I am trying to make a fast convert of a batch of files like this:
convert ./src/*.png -set filename: '%t' -gravity West -draw 'image over 0,0 424,600 "./panel.png"' ./dest/%[filename:].png
which is pretty similar to COMPOSITE:
convert ./src/*.png ./panel.png -set filename: '%t' -gravity +0+0 -composite ./dest/%[filename:].png
except the last one is not working and just making one first crappy-looking file.
Looks like it's bug?
Does anybody know how to make it more correct with -composite?
for|awk|ls|find for each file in shell is not acceptable - because that is slower than the first example.
Read in the list of files,
set their output filenames,
include the IM special image placeholder "null:",
read in your overlay image,
optionally, set the geometry,
and composite that overlay onto all the other images with "-layers composite".
That null: separates the original input file list from the overlay image so ImageMagick knows where in the stack you want to start doing the composite.
Try something like this (one step per line for readability):
convert ./src/*.png \
-set filename: '%t' \
null: \
./panel.png \
-layers composite ./dest/%[filename:].png
You could use Imagemagick mogrify command. See http://www.imagemagick.org/Usage/basics/#mogrify and http://www.imagemagick.org/Usage/basics/#mogrify_compose
cd to input directory
mogrify -format png -path ./dest -gravity West -draw 'image over 0,0 424,600 "./panel.png"' *.png
Looks like it's bug?
Not a bug. Your second command is telling ImageMagick to consume all files matched into an image stack, and composite it as one.
You can attempt the same solution with the mogrify utility, but I believe it would be way simpler if you expand the bash script with a single for loop.
for f in $(ls src/*.png)
do
dest=$(basename $f);
convert "$f" ./panel.png -gravity West -composite "./dest/$dest"
done
Related
I want to split some images by percentage using ImageMagick.
To be more precise, I want to split an image into two images. The output-image of the left side should be 55% of the left side of the original image, the output-image of the right side should be 55% of the right ride of the original image.
(In case I am not making myself clear: The point is that there is sometimes important information in the middle of the images and this information would be cut off if we split the images exactly in the middle.)
What I have so far is this: mogrify -crop 55%x100% +repage -path ./cropped *.jpg
So at the moment, I am splitting the image into two and saving it in the "cropped"-folder. BUT, only the left side is 55% of the left side of the original image, the right side is 45% of the right side of the original image.
As this is my first time working with ImageMagick, I would really appreciate your help!
Here is another approach to splitting an image to create two output images that are 55% from the left and 55% from the right of the original...
convert input.png -set filename:0 "%[t]" \
\( +clone -roll +55+0% \) -extent 55x100% "%[filename:0]_%d.png"
That starts by setting a file name variable to use for the output. Then it makes a clone of the input image, and rolls it 55% to the right. The result is moving the rightmost 55% of the image out of the frame to the right and back into the frame on the left. Then after the parentheses a simple -extent operation keeps the leftmost 55% of each image. The output files are named from the input file with a "_0" or "_1" added.
As fmw42 suggested, you can make a loop command to run on multiple inputs, and include the path names in the command for your output files.
I think you would have to run a script loop over each image and use convert rather than mogrify. Mogrify can only output one image for each input image. You do not say what platform/OS or what version of ImageMagick. The following assumes Unix-like system with IM 6 and is one way to do that.
infile="original_file.suffix"
convert "$infile" -set filename:fname "%t" -write mpr:img +delete \
\( mpr:img -gravity west -crop 55x100%+0+0 +repage +write "path_to/cropped/%[filename]_0.suffix" \) \
\( mpr:img -gravity east -crop 55x100%+0+0 +repage +write "path_to/cropped/%[filename]_1.suffix" \) \
null:
Or, you could just run mogrify twice. Once for the left side and once for the right side. Use -gravity to control which as in the convert command.
I'm trying to use ImageMagick to compose different pieces of a rendered PDF into a target. E.g., I want to have ImageMagick render the PDF at 300dpi, then create a 300x400 pixel output image, then take from the PDF the area 10x20+30+40 and place it in the target (300x400 pixel image) at 12,34. Then take another (and a third and fourth) chunk at different coordinates with different sizes and place them at different places.
I cannot seem to figure out how to do this in one go, and doing it in multiple runs always re-renders the PDF and takes awfully long. Is this even possible?
Here's an idea of how you can approach this. It uses the MPR or "Memory Program Register" that Fred suggested in the comments. It is basically a named chunk of memory that I write into at the start and which I recall later when I need it.
Here is a rather wonderful start image from the Prokudin-Gorskii collection:
The code resizes the image and saves a copy in the MPR. Then, takes a copy of the MPR, crops out a head, resizes it and composites the resized result onto the resized original at a different location and then repeats the process for another head.
magick Prokudin.png -resize 300x400\! -write MPR:orig \
\( MPR:orig -crop 50x50+180+84 -resize 140x140 \) -geometry +10+240 -compose src-over -composite \
\( MPR:orig -crop 40x40+154+184 \) -geometry +40+100 -compose src-over -composite \
result.png
If you have trouble understanding it, try running it with the second or third line omitted so it just does one head ;-)
Hopefully it covers all the aspects of your question and you can adapt it to your PDF.
I have different images in different .png files like the following:
I'd like to find a command line tool that allows me to mix all those images into a single one while generating a new .png file:
I know that using ImageMagick we can manipulate images from the command line in many useful ways. I've looked for questions under the imagemagick tag here on stackoverflow but I didn't find anything similar to what I need and the man pages of the ImageMagick tools like convert and compare are extremely extensive. Is it even possible to solve using ImageMagick? If so, how can I do it?
Edit:
Individual images files:
In ImageMagick 6, you can do the following to composite each image onto the circle.
Unix Syntax:
convert circle.png \
cloud.png -geometry +60+10 -compose over -composite \
phone.png -geometry +40+100 -compose over -composite \
arrow.png -geometry +120+100 -compose over -composite \
result.png
Windows Syntax:
convert.exe circle.png \
cloud.png -geometry +60+10 -compose over -composite ^
phone.png -geometry +40+100 -compose over -composite ^
arrow.png -geometry +120+100 -compose over -composite ^
result.png
If using ImageMagick 7, change convert to magick. On Windows be careful as there is a Windows convert.exe. You may want to rename the ImageMagick convert.exe to something else and use that above.
The \ and ^ are line feed characters so that the command can be written on multiple lines. If you make this all one line, then remove those characters.
I am trying to apply watermark to an image of any size using two steps in one command line:
Tile small png image and overlay it over the target image.
Overlay a logo at top left corner without tiling.
I don't understand the imagemagick command line principles and can't create a command line to make these operations without creatig temporary file between steps 1 and 2. But I am sure this is possible :)
Please help me to do that.
Thanks.
There are many ways to achieve this, but the simplest would be to leverage ImageMagick's Stack notation "()".
Simply group the first step into a command wrapped in parentheses, and omit the output filename.
convert \( \
wizard: \
-size 480x640 \
-background transparent \
tile:label.png -composite \
\) \
-gravity NorthEast rose: \
-composite output.png
The above will compose the label.png as a repeating image over the wizard: image. Note, in this example I provided the -size and -background attributes. The result of the Image Stack will be accepted as the input image for the second -composite operation; which, places the rose: image in the top right.
I have around 100 pictures that i want to add white border to it all at once.
I use Linux and also use gimp ,.. please suggest me something to do so online of offline.
and one more thing that i have tried convert option on imagemagick but nothing happen.
If you want to do 100 all at once you will be best off using ImageMagick's mogrify command like this to add a 10 pixel white border around all images:
mogrify -mattecolor white -frame 10x10 image*.jpg
If the images are not all in a single directory, you can do the following which will do the same thing across all subdirectories of the one you are currently in:
find . -name \*.jpg -exec convert "{}" -mattecolor white -frame 10x10 "{}" \;
Obviously you can change the 10 to a different number of pixels if you wish.
Please make a backup before using this as I may have misunderstood your needs.
Updated
If you want a drop shadow, you really need to be working with PNG rather than JPG since the former supports transparency and the latter doesn't - but IM can convert your JPEGs to PNGs anyway. I use the following command for drop shadows:
convert image.jpg \( -clone 0 -background black -shadow 80x3+0+8 \) -reverse -background none -layers merge +repage image.png
So, I would apply that to a pile of images like this:
#!/bin/bash
for f in *.jpg; do
new=${f%%jpg}png # Work out new name = original name minus "jpg" + "png"
echo Processing $f into $new
convert "$f" \( -clone 0 -background black -shadow 80x3+0+8 \) -reverse -background none -layers merge +repage "$new"
done