Copyright © Fred Weinhaus My scripts are available free of charge for non-commercial (non-profit) use, ONLY. For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net. If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment. Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php Please read the Pointers For Use on my home page to properly install and customize my scripts. |
Transforms an image to place it in a region of a tshirt image |
last modified: July 17, 2020
USAGE: tshirt [-r region] [-c coords] [-f fit] [-g gravity] [-v vshift]
[-o offset] [-R rotate] [-l lighting] [-s sharpen] [-b blur] [-d displace]
[-a antialias] [-A attenuate] [-B brightness] [-S saturation] [-C compose]
[-o opacity] [-E] [-D directory] infile bgfile [maskfile] outfile
-r ... region ...... region is a simple rectangle defined as the WxH+X+Y PURPOSE: Transforms an image to place it in a region of a tshirt image. DESCRIPTION: TSHIRT transforms an image to place it in a region of a tshirt image. The transformed image will display hightlights from the tshirt image and be distorted to match the wrinkles in the tshirt image. ARGUMENTS: -r region ... REGION is a simple (unrotated) rectangle defined as the WxH+X+Y of the region in the tshirt (bgfile) where the overlay image (bgfile) will be placed. The components of W, H, X, Y are integers and specify the width, height, upperleft xoffset and yoffset of the rectangle. Only one or the other of region or coordinates should be specified. But coordinates take precedent. -c coords ... COORDS are the 4 x,y corners of the region in the tshirt (bgfile) where the overlay image (bgfile) will be placed. The coordinates must be listed clockwise from top left corner; coordinates are integers>=0. Only one or the other of region or coordinates should be specified. But coordinates take precedent. Coordinates are not restricted to a rectangle and the region defined by the coordinates can have rotation. -f fit ... fit can be: crop (c), distort (d) scale (s), top (t) or none (n); If crop, then the overlay image (infile) will be resized to the width of the region (or coordinate area) and cropped if needed. This will not distort the image. The image will not be cropped, if its height is smaller than that of the region and it will then be aligned at the top of the region. If distort, then the overlay image (infile) will be resized to fit exactly to the region (or coordinate area). This will cause distortion, if the aspect ratio of the overlay image (infile) does not match the aspect ratio of the region (or coordinate area). If scale, then the overlay image (infile) will be resized so that the larger dimension fits the region (or coordinate area) and the other dimension is smaller. The resized overlay image (infile) will be centered in the region. If top, then the overlay image (infile) will be resized so that both width and height fit into the region without distorting and placed at the top center of the region. The default=none, which means that the image will be resized to fit the width of the region (or coordinate area) and aligned at the top of the region. If the height of the resized image is larger than the height of the region, it will extend past the bottom of the region. -g gravity ... GRAVITY for selecting the crop location. The choices are: north (n), south (s) or center (c). The default=center. -v vshift ... VSHIFT is the vertical shift of the crop region with respect to the gravity setting. Values are integer. Negative is upward and positive is downward. The default=0 (no shift). -o offset ... OFFSET is an additional x,y offset of the region or coordinates in order to make positional adjustments easier. This is a comma separated x,y pair. Values are ositive or negative integers for x and y. The default is no offset. -R rotate ... ROTATE is an additional clockwise positive rotation in order to make orientational adjustments easier. Values are -360<=float<=360. The default=0. -l lighting ... LIGHTING is the contrast increase/decrease for highlights to apply to the overlay image (infile). Values are -100<=integer<=100. Positive values increase contrast and negative values decrease contrast. The default=20. -s sharpen ... SHARPEN is the sharpening to apply to the overlay (infile) image. Values are floats>=0. The default=1. -b blur ... BLUR is the blurring to apply to the displacement map to avoid jagged displacement. Values are floats>=0. The default=1. -d displace ... DISPLACE is the amount of displacement for the distortion of the overlay (infile) image. Values are integers>=0. The default=10. -a antialias ... ANTIALIAS amount to apply to alpha channel of tshirt (bgfile) image. Values are floats>=0. The default=2. -A attenuate ... ATTENUATE is the attenuation of the effect of coarse texture from the background (bgfile) image from showing on the overlay (input) image. Values are floats>=0. Larger values blur the tshirt texture more which attenuates the effects. The default=0. -B brightness ... BRIGHTNESS percent change to the input overlay image. Value are positive or negative integers. The default=0. -S saturation ... SATURATION percent change to the input overlay image. Values are positive or negative integers. The default=0. -C compose ... COMPOSE method to merge the overlay (infile) image with the background (bgfile). Choices are: hardlight (h), multiply (m), screen (s) or over (o). The default=hardlight. The choice of hardlight allows the overlay image to be brighten and darken according to the folds in the tshirt. The other compose methods will not do that. The choice of over simply places the overlay image unchanged upon the tshirt image. The choice of multiply does a multiply operation, which may change colors and would need adjustment by -B and -S arguments. -O opacity ... OPACITY to apply to the image. Values are 0<=integers<=100. The default=100 (fully opaque). -E ... EXPORT the lighting image, displacement map and other needed parameters for use with a condensed script to repeat the processing on the same tshirt image apart from coloring for faster processing. The lighting image will be named lighting.png and the displacement map will named displace.png. The other arguments will be displayed to the terminal and can be copied and pasted into my script, tshirtwarp. -D directory ... DIRECTORY to write all the exported data when using the -E export option, including a text file called tshirtdata.txt that contains the same textual parameter data sent to terminal. The directory can be specified in the tshirtwarp script to import all the needed images and textual data. This permits one tshirtwarp script to be used with all style tshirts, rather than save a customized script for each style tshirt. If the directory does not exist, it will be created. IMPORTANT: The nominal transformed image will not fit the exact height of the region or coordinates area, if the aspect ratio of the image differs from that of the region or coordinate area. The process maintains the correct aspect ratio of the input image. Depending upon the aspect ratio, the transformed image may be shorter or taller than the height of the region. To crop the image so that it fits the region or coordinate area, use the -f option. REQUIREMENTS: IM 6.5.3.4 due to the use of -compose displace. CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk. |
Example 1 -- Gray Tshirt and Opaque Image |
Input (Overlay) Image |
Background (Tshirt )Image |
Background (Tshirt )Image With Selected Bounding Box |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Example 2 -- Blue Tshirt and Opaque Image |
Background (Tshirt )Image |
Arguments: |
Example 3 -- Gray Tshirt and Transparent Image |
Input (Overlay) Image |
Background (Tshirt )Image |
Arguments: |
Example 4 -- Textured Gray Tshirt and Opaque Image |
Input (Overlay) Image |
Background (Tshirt )Image |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Example 5 -- Animations With 2 Images and Different Fits |
Input (Overlay) Image 1 |
Input (Overlay) Image 2 |
Background (Tshirt )Image |
Background (Tshirt )Image With Selected Bounding Box |
Arguments: |
Arguments: |
Arguments: |
Arguments: |
Example 6 -- Masking |
Input (Overlay) |
Background (Tshirt ) Image |
Background (Tshirt ) Image With Rectangle |
Mask File |
Arguments: |
What the script does is as follows:
|