How to crop curved areas with ImageMagic or with a template - imagemagick

another subject could be: How do i crop a t-shirt out of a pattern image(image is big enough we have huge printers)
Everyone,
Could you please guide me on what the commands would be to do a cut of an image. Im new to ImageMagic and did not see anything that was exactly (only partially) to handle my issue.
We get already presized image files to go on a mens or womens tshirt (soon dress). To save spraying all the ink we would like to cut the image to predefined coordinates for each size, and type.
How do I first determine (given a template files) all the coordinates and create commands for each size and style.
Will this work in .NET?
I can still work with php, and c++ if you prefer.
Here is a link to an example of what needs to be done. http://www.relationship1.com/help.zip
Inside help.zip is
STYLE1__XS_TEMPLATE_FILE_PDF.pdf – outline of what needs to be CROPPED out for this size and style
STYLE1_XS_asset_before.png – this is the image before
STYLE1_XS_TEMPLATE_FILE_PHOTOSHOP_METHOD.ODS – this is some photoshop file they use to do this manually with (there is some hidden layer in here)
STYLE1_XS_TFILE_PDF_WITH_IMAGE_AND_TEMPLATE.pdf – this is what the step would look like right before its completed
STYLE1_XS_TT_asset_completed.png – this is the desired input

the following is the answer
static void Main(string[] args)
{
using (MagickImage mask = new MagickImage(#"c:\help\maskO2_XS.png"))//black where the cut would be white where the asset is
using (MagickImage image = new MagickImage(#"c:\help\STYLE1_XS_asset_before.png"))//pattern file
{
mask.Resize(image.Width, image.Height);
image.Composite(mask, CompositeOperator.Bumpmap);
image.Write(#"c:\help\file_out.png");
}
}

Related

imagemagick cropping image creates jagged edges or saw-tooth shapes

The above pic (looks like zoomed one ) is from first level conversion from 1.Ai file 1_cropped.AI file what I get after cropping. I don't do resize during cropping it gets automatically resized.
I am trying crop an image, Seems without +repage imagemagick unable to crop. The problem is a simple crop created the jagged lines as you can see from the snapshot taken from a portion of image.
How to remove this. Some where in SOF post I found a recommendation to use "Gaussian blur" but didn't find a proper command to do the same. Many thanks! I am doing just the crop and no resizing.
Original : Due to copyright can't show the entire image. But below is one section:
Looking into : http://www.imagemagick.org/Usage/antialiasing/ now but unable to smoothe the 'stair case' or 'jaggies' so far.
UPDATE from the comments:
Yes the input is AI and output is almost all format AI/SVG/PNG/GIF/JPEG/BMP. So for smaller resolution files such as png/GIF I don't get that jagged shapes I I tried turning on anti-aliasing , blurring and guassian-bluring but no luck. I think the repaging zooms the image which I don't need, is it possible to set the canvas somehow so the original resolution is kept intact when converting from AI to AI? Yes initially I convert AI to AI after cropping and than feed the converted AI for further processing. The stair-stepping appears from first level AI to AI file conversion itself.

How to recolor an image on specific area?

I'm trying to create an iOS recoloring app (this is my reference), and i need to know how recolor some portion of the image when user taps on a given area. All the loaded pictures will be black/white initially.
Is there any prebuilt library? Or which graphics framework should i use?
Any help will be appreciated.
If what you are looking for is adding/replacing the colour within a certain shape and edges are really important (as in the example) then you should be looking into vectorised drawing.
What this means is every shape in your image would have an actual object representation in your code, and you could easily interact with that object to do whatever you want (i.e. tap gestures to change colour, zoom etc.).
This however, means that you can't simply use .jpeg images, and you need to use images in vector format, such as .svg or CorelDraw.
As a reference, check out SVGKit, which is an excellent library for working with SVG images.

Change the background from transparent to some color using gimp

I've large set of images. I wan't to chage their background to specific color. Lets say green. All of the images have transparent background. Is there a way to perform this action using python-fu scripting in Gimp. Or some other tool available to do this specific task in automated fashion.
Yes there is -
Although this question is not an exact duplicate, i is not practical to just type in the basics of creating a Python plug-in every time someone asks to automate some task in the GIMP
I will have to ask you to look at GIMP: Create image stack from all image files in folder and maybe some other python-fu related answers for the basics.
After you get a simple "hello world" script going, simply
register a script that asks for
a string with the desired folder, use Python's os.listdir, or glob.glob to fetch the paths
to the iamge files, and simply loop through them repeating calls to:
image = pdb.gimp_file_load (...)
image.new_layer(pos=1, fill_mode = FOREGROUND_FILL)
pdb.gimp_file_save(...)
pdb.gimp_image_delete(image)
The parameters to the PDB calls are easy to check at GIMP's help procedure browser -
the image's new_layermethod is not really documented, and can replace 3-4 pdb calls - the possible parameters to it are: "name", "width", "height", "offset_x", "offset_y",
"alpha", "pos", "opacity", "mode", "fill_mode",
all of which are optional. "pos" is the layer position: 0 is at the top of the image. "1" would be just bellow the topmost layer.
It should be clear that the gimp_image_delete call will just remove the image from memory - not the file from disk. Simply de-referencing it on the Python side won't make GIMP forget it. Likewise, if you want to interact with any image open in this way, you have to call pdb.gimp_display_new for that image.
You should be able to accomplish this by simply setting the background color to your desired color and then simply flatten the image which will make all transparent areas become set to the current background color.
pdb.gimp_palette_set_background( 'green' )
image = pdb.gimp_file_load ('myImage.png')
flatLayer = pdb.gimp_image_flatten( image )
pdb.gimp_file_save( image, flatLayer, 'myFlatFile.png' , 'myFlatFile.png')

Bulk creation + edit images

I currently use photoshop + datasets to automatically create CTA buttons for testing on a clients website. The dataset often contains text and other changes like underline or background colour, as well as alignment and font formatting.
Typically these can run into the thousands, which photoshop handles very well but the task is technical and not graphical. For me photoshop is overkill for the task.
Is anyone aware of a solution that is more code-friendly? I am currently playing around with canvas on HTML and fabric.js. This allows me to manipulate a template image, and I hoping I can pipe in code to create a number of .png output images.
Canvas would be well suited to your automation
First, create a base .png and then programmatically alter it in thousands of ways.
Save the results to appropriately named .png files.
You could even create an on-screen viewer that dynamically creates thousands of variations. The client(s) could browse the dynamically created images and select the variations that interest them. That would eliminate the need for thousands of saved files.
Here are just a start of canvas commands you can use to automate:
Apply text:
context.font("italic 14pt Verdana");
context.textAlign = textAlign; // left|right|center
context.fillText("anyText", x,y);
Underlines are just a bit trickier:
// use measureText to get the text width
var textWidth =context.measureText(text).width;
// 1-time only, pre-calculate all the “Y” underline offsets for each font you use
var ULOffset=lookupULOffset(font,fontSize);
context.moveTo(x,y+ULOffset);
context.lineTo(textWidth,y+ULOffset);
context.stroke();
Change background color or anything else that you've created a sub-layer for!
Like Photoshop Canvas has an excellent set of compositing operations.
Source-over
Source-in
Source-out
Source-atop
Lighter
Xor
Destination-over
Destination-in
Destination-out
Destination-atop
Darker (this has been deprecated for some reason??)
You also can apply an alpha when drawing a layer as well as an alpha while drawing any canvas shapes.
In addition, check online for many image filters that have been created for canvas.
And that's just be beginning...
Happy Automating!

How can I request an image and return it as black and white in rails?

I'd like to have an image and a combo box with 2 options: color, and black and white. When the combo box selection changes, I'd like to return the image as black and white and have this done dynamically on the server (so I don't have to store the black and white image on the server).
I was thinking I could point the img tag at a url like "/images/blackandwhite/120" where 120 is the image id of the color picture, and have it dynamically turn the image to black and white and return the image data to the browser.
Is this possible? How would I do this?
Storing two copies of the image will be much more efficient than processing the image everytime it is requested.
However, you might be able to get away with using CSS image filters:
filter:gray
Paperclip, by default, is prepared to "alter" images. The objects used for modifying the images are called "processors". Paperclip comes with just one processor, for making thumbnails.
Processors don't do what you want; they "process" the image "once", when the original image is loaded. They require the "processed" images to be stored permanently. If you erase the images, they don't re-create them; they throw an exception.
However, by looking at the source code you can learn how to do what you want.
Here's the relevant code that makes the thumbnails). As you can see, it simply calls "convert" (the Imagemagick command) with certain parameters.
This should point you in the right direction. For example: You could create a method in your model that creates the black and white version of your image inside /tmp/, and probably another one for deleting it. Your controller would have to call the former, send the image, and then delete the file.
There are several options in creating black and white images with Imagemagick - for example, you can create "real" black and white (2 colors only) or grayscale images. This forum post details the Imagemagick commands for several options.
Finally, a suggestion. If instead of this
/images/blackandwhite/120
Consider using this:
/images/120?color=blackandwhite
This way, you will not have to add additional routes, and your controller will be more restful. Then, on your show action, you just have to check whether param[:color] equals "blackandwhite"

Resources