Inquiry: resize, sharpen, frame and write text in img frame

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?".
Post Reply
snahl
Posts: 4
Joined: 2012-03-09T19:29:33-07:00
Authentication code: 8675308
Location: Switzerland

Inquiry: resize, sharpen, frame and write text in img frame

Post by snahl »

Hello,
I hope someone can help me to get started with ImageMagick so that the output pretty much equals the image shown here (my image at my website):
http://bit.ly/zZmuJx

I'd like to use ImageMagick in a way so that it processes a given image in TIF or JPG format the following way, eventually also to process a batch of images in a given folder.

-convert to a width of max. 1000px and a height of max. 800px depending on the orientation (landscape or portrait) of the image being processed.
-convert from 16bit Adobe RGB or ProPhotoRGB to 8 bit sRGB (perceptual)
-sharpen the image
-put a border color #222222 of 1px all around the image
-put a frame of 30 pix width with color #666666 all around the image (including the just created border)
-inside the bottom of this frame write a predefined text with one variable text element the filename of the image processed. Something like: Copyright 2012, Name, http://WEB-sitename, Name of the image file processed.
-save as jpg or png

An almost exact example for expected output is show at the beginning of the post.
Thanks for your feedback.
Hans
Dig-IT-all
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Inquiry: resize, sharpen, frame and write text in img fr

Post by fmw42 »

Most is straightforward. The main issue is what do you mean by:
convert to a width of max. 1000px and a height of max. 800px depending on the orientation (landscape or portrait) of the image being processed.
If the image is portrait, what height do you want (1000?) and what limits on the width.

If the image is landscape, what width do you want (1000 or 800?) and what limits on the height.

Do you want max of 1000x800 for landscape and 800x1000 for portrait? Is that what you are requesting?

What do you want to do if the one dimension is 1000 but the other ends up larger than 800? Do you want to crop it or force the size to 1000x800 by changing the aspect ratio (distorting the image)? For example if your image is square to start with?

see
http://www.imagemagick.org/script/comma ... p#geometry
http://www.imagemagick.org/Usage/resize/#space_fill

A conditional test may be necessary to test for landscape or portrait and then decide to pad or crop.

See my script, aspect, at the link below. Scripts are unix/bash shell scripts.


You don't say what version of IM and platform you are using. Windows syntax and scripting is different.

See
http://www.imagemagick.org/Usage/windows/

For any given image, you will need to know the profile imbedded in the image to set up the profile conversion correctly. Otherwise just use -colorspace sRGB.
-put a frame of 30 pix width with color #666666 all around the image (including the just created border)
is this 30 pixels over and above the already 1 pixel or is it an additional 29 pixels?

try something like:


convert yourimage.jpg -colorspace sRGB -resize 1000x1000 -sharpen 0x3 \
-bordercolor "#222222" -border 1 -bordercolor "#666666" -border 30 \
-gravity south -fill red -font Arial -pointsize 24 \
-annotate +0+0 "this is some text" yourimage_test.png


For better quality one needs to use the exact profile for the input image.

see
http://www.imagemagick.org/Usage/formats/#profiles

To get other information from the image into the caption, see
http://www.imagemagick.org/Usage/basics/#set

For those new to IM, good reading is at:

http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/script/comma ... ptions.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
snahl
Posts: 4
Joined: 2012-03-09T19:29:33-07:00
Authentication code: 8675308
Location: Switzerland

Re: Inquiry: resize, sharpen, frame and write text in img fr

Post by snahl »

Thank you Fred for your detailed answers. This is great and I guess this should get me started just fine.

Following the answers to your questions:
Do you want max of 1000x800 for landscape and 800x1000 for portrait? Is that what you are requesting?
Kind of, basically yes.
I want to keep the aspect ratio of a given image intact. I shoot with 2 cameras (Canon G12 and Nikon D300) and both have different aspect ratios with a max width of 1000px and max heigt of 800px.
After processing all images should be within that boundry. Given the 2 Aspect ratios, the heights and widths will vary for landscape and portrait images.

what version of IM and platform you are using
IM Version: ImageMagick-6.7.5-10-Q16-windows-x64-dll.exe
OS Version: Windows7 64-bit

is this 30 pixels over and above the already 1 pixel or is it an additional 29 pixels?
The 1 pixel frame is all around (top, right, bottom, left) the image, following that is the 30 or 29 pixel frame all around as well. That 1px difference does not really matter much.

For better quality one needs to use the exact profile for the input image.
The embedded profiles are either:
- Adobe RGB (1998)
- sRGB IEC61966-2.1
- ProPhoto RGB

The destination color space should allways be: sRGB IEC61966-2.1, so sometimes there is no conversion to another color space.

try something like:
convert yourimage.jpg -colorspace sRGB -resize 1000x1000 -sharpen 0x3 \
-bordercolor "#222222" -border 1 -bordercolor "#666666" -border 30 \
-gravity south -fill red -font Arial -pointsize 24 \
-annotate +0+0 "this is some text" yourimage_test.png
Thank you, I will certainly try this code and post back.

-annotate +0+0 "this is some text" yourimage_test.png
Does the last part of this command include the file name of the image processed?

How could the file name be used as a variable derived from the currently processed image ?
The final goal is to apply the conversion commands to several images without typing each image file name for input and output.

I'd assume the commands given above will be parsed by the windows version of IM.
I will work on it this evening and post back.

Greets, Hans.
Dig-IT-all
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Inquiry: resize, sharpen, frame and write text in img fr

Post by anthony »

Convert has a input and a output file name. One at the start, the other at the end.

These are implied read image and write image operations.

mogrify uses the same flenamefor both the input and the output. In fact in IMv6 mogrify uses any filename it finds on the command line (non-option and associated arguments) as being a input/output filename, unless its output is redirected by -format or -path options



FUTURE:...
In IMv7 I plan to still allow this but provide a special '--' option as a seperator between operations, and the fileanmes. A warning will issued if no such option is seen, but it will still continue as per IMv6 style. The main reason for this is you will be able to read 'secondary images' for composition in IMv7 mogrify!

That is the plan anyway, but I am no where up to that part of the implementation yet.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Inquiry: resize, sharpen, frame and write text in img fr

Post by fmw42 »

Unfortunately, I still do not understand what you want for max sizes when landscape and when portrait. Is that 1000x800 for landscape and 800x1000 for portrait?

With regard to using profiles, you have to know which one is being used by which image and specify that. The other way is to extract it from the identify -verbose yourimage information, put it into a variable and then use that variable when you specify -profile someprofile.

Windows syntax is somewhat different from my unix command above. In windows parenthesis are not escaped by \, end of line \ are replaced by ^ and % must be escaped by %%. See http://www.imagemagick.org/Usage/windows/

You have to specify the finename you want as output to convert. Mogrify will use the same filename as the input and can process a whole directory of files. But use -path to a new directory so you don't overwrite your good images with bad ones. see http://www.imagemagick.org/Usage/basics/#mogrify.

For convert to use the input filename, you have to extract that and put it into a variable.

In unix, it would be something like

infile="yourimagename.jpg"
inname=`convert $infile -format "%t" info:`

That put inname="yourimagename" without the suffix. You can add other things to the output by

outname="${inname}_whateveryouwanthere.jpg"

But again this is unix syntax and you would need to read the windows document above for how to do that under windows.
snahl
Posts: 4
Joined: 2012-03-09T19:29:33-07:00
Authentication code: 8675308
Location: Switzerland

Re: Inquiry: resize, sharpen, frame and write text in img fr

Post by snahl »

This is great, thank you Fred, you're providing very valuable information to work with.
Unfortunately, I still do not understand what you want for max sizes when landscape and when portrait. Is that 1000x800 for landscape and 800x1000 for portrait?
Sorry for not being clear enough.
Different cameras, different aspect ratios. So the output size varies. What I envision is as follows:
- for landscape images a max. width of 1000 px for all images processed, thus the output height varies.
- for portrait images a max height of 800 px for all images processed, thus the width varies.
In other words the IM-script must first check the image orientation and then use the image aspect ratio to calculate the new height for a landscape image or width for a portrait image.
The output would then become:
- for landscape images: 1000 px width by %var_height px height
- for portrait images: 800 px height by %var_width px width

By using the term 'maximum' I envision an option to enter that value for heights AND widths before applying the script to images to be processed.
A maximum value of 1000px or 800px respectively because for desktop-screens or TVs only very few of both use larger display widths or heights (->resolutions).
For iPhones are Androids the same values would be just a chunk smaller ( little less than 480 x 800) but certainly not larger.

Thank's a bunch for your kind assistance to get me going with IM.
There is a bunch of information on your WEB-Site so that I should be able to figure this out.

I am off to Argentina tomorrow, so my feedback will be rather delayed during the next 3-4 weeks.
Greets, Hans.
Dig-IT-all
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Inquiry: resize, sharpen, frame and write text in img fr

Post by fmw42 »

In unix, you should be able to test for aspect by

aspect=`convert image -format "%[fx:(w/h)>1?1:0]" info:`

aspect=1 means landscape
aspect=0 means portrait

Then use an if test to process

if [ $aspect = 1 ]" then
convert image -resize 1000x1000 ... output
else
convert image -resize 800x800 ... output
fi

something like that should get you started. If you need to crop further in the other dimension or pad, you can see my script, aspect, below.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Inquiry: resize, sharpen, frame and write text in img fr

Post by anthony »

Just resize into a 1000x800 box. that is your 'output area' is it not?
Images in landscape will be limited by the 1000 width, images in portrait will be limited by the 800 height.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply