creating a "product"

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
holden
Posts: 79
Joined: 2013-02-07T08:22:57-07:00
Authentication code: 6789

creating a "product"

Post by holden »

Hey all, I'm trying to figure out a good way to do this, any input is appreciated. I need a way to create a template (actually many kinds) for print purposes, but for example lets say a 4"x6" with .25" borders. So, being that we would want it at 300ppi, it would start at 1200x1800px. Next the borders, so they would be 75px wide. Now I need to fit an image of varying resolution into the leftover middle "hole," either scaling up or down depending on the initial resolution to 300dpi. I am figuring out how to create the appropriately proportioned image already, I just need some smart input on how to go about this in a clean way. Thanks.

*Edit options could be generating the output image on the fly or creating templates to composite into, or perhaps something better
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: creating a "product"

Post by snibgo »

So the dimensions within the border are 1200-150 = 1050 pixels by 1800-150 = 1650 pixels. Your input images may not have this aspect ratio. In that case, do you want to (a) trim part of the image away, (b) keep the entire image by adding more white border or (c) change the aspect ratio of the image?

The solution would include the "-resize" command in one of its forms. Then you might add a border, or simply centre it on a 1200x1800 white canvas. Something like this:

Code: Select all

convert -size 1800x1200 xc:pink ( in.png -resize 1650x1050 ) -gravity center -composite out.png
I have used a pink background so I can easily see the boundary of the image.

See http://www.imagemagick.org/script/comma ... ptions.php
snibgo's IM pages: im.snibgo.com
holden
Posts: 79
Joined: 2013-02-07T08:22:57-07:00
Authentication code: 6789

Re: creating a "product"

Post by holden »

Thanks for the reply, I will give that a try. Also,there are different resizing algorithms, is the default good for both upscaling and downscaling? I imagine I will have to run a sharpening process as well.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: creating a "product"

Post by snibgo »

For me, the default settings for enlarging and reducing are fine. viewforum.php?f=22 has discussions of non-default settings.

When the input is a photograph, a final sharpening is generally beneficial, with a sigma somewhere near 1.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: creating a "product"

Post by fmw42 »

If I follow this thread, resizing alone will preserve the aspect ratio of the input and so may not fit into the area desired. You would need either to resize normally and use -extent to fill in with your color or resize using the ^ option and center crop the image. Either way, it will not hurt to add that to your command if the resize turns out to be correct. If you use ! option, then the image may be distorted but will fit exactly.

See
http://www.imagemagick.org/script/comma ... p#geometry
http://www.imagemagick.org/script/comma ... php#extent
http://www.imagemagick.org/script/comma ... s.php#crop
http://www.imagemagick.org/Usage/thumbnails/#pad
http://www.imagemagick.org/Usage/thumbnails/#cut
holden
Posts: 79
Joined: 2013-02-07T08:22:57-07:00
Authentication code: 6789

Re: creating a "product"

Post by holden »

Thanks snibgo, that code seems to be exactly what I need. :D

@fmw42- yes that is my next step, the -extent part. Some people want to have odd sized images on a certain print size without cropping. Thanks for the links and advice.

*as a side note I may have found a bug, when using the crop operator without coordinates, eg. 4x6 vs. 4x6+0+0, you get weird output file names, usually output-0.jpg, output-1.jpg, up to 5, and no output.jpg. Also doing the crop by % generates hundreds of temp files it seems, even on smallish <1000px image (this could be dependent on coords as well, I stopped trying it this way).
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: creating a "product"

Post by snibgo »

For the crop feature (not a bug), see http://www.imagemagick.org/script/comma ... s.php#crop
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: creating a "product"

Post by anthony »

holden wrote: *as a side note I may have found a bug, when using the crop operator without coordinates, eg. 4x6 vs. 4x6+0+0, you get weird output file names, usually output-0.jpg, output-1.jpg, up to 5, and no output.jpg. Also doing the crop by % generates hundreds of temp files it seems, even on smallish <1000px image (this could be dependent on coords as well, I stopped trying it this way).
That is a feature. Without a offset, crop will generate multiple image tiles.
http://www.imagemagick.org/Usage/crop/#crop_tile
As a result of this IM then needs to save multiple images.
In GIF you would get a single image of all the tiles, for PNG and JPEG separate files as that format can only hold one image per file.
See Adjoin - writing multiple images
http://www.imagemagick.org/Usage/files/#adjoin
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply