Search code examples
graphicsmagick

Change all solid parts of eps file to certain color in graphicsmagick


Very new to graphicsmagick but I can see that it is very powerful. I have a decal site and I am looking to update my images. I do this in my spare time so I don't really have budget for anything so I try and do all work I can myself.

All of the 'patterns' I use are in EPS vector format. They are all monochrome. I send this EPS pattern to my vinyl plotter and it cuts the shapes out on whatever colored vinyl I have loaded.

For the website images what I would ultimately like to do is take an image of the back glass of a truck, and overlay the EPS in one of the colors I sell with a transparent background. This would give my customers an idea of how the decal would look on their vehicle.

Is it possible to use graphicsmagick to generate different versions of each EPS in different colors or will I have to create a version of the EPS for each color?

Does anyone know of any good examples for doing any of this? I've succesfully resized and merged an EPS with another image, but I'm a bit lost when it comes to adding transparency. Do I need to select a color? If so, do I choose white as that's the background color of the resulting jpg? The EPS files don't have a background color as far as I know.

Any help is most appreciated.


Solution

  • Assuming your EPS represents a black decal on white, you can use "-transparent white" to make the white part (the vinyl scrap) transparent, and "-fill #FF0000 -opaque black" to make the rest of it the color of your vinyl (in this example, red, which is hex #FF0000), and write the result as a PNG with transparency:

    gm convert decal.eps -transparent white -fill "#FF0000" \
               -opaque black -matte decal_red.png
    

    Then rescale decal.png and overlay it on your truck image as you have already done:

    gm convert truck.jpg -draw "image over x,y 0,0 decal_red.png" \
               truck_with_red_decal.jpg
    

    where you replace x and y with the coordinates of where you want to place the upper left corner of the decal on the truck image. "0,0" are the width and height of the overlay image (if 0 they default to the dimensions from the image file)