Resizing and Colour change

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
TheLads
Posts: 3
Joined: 2017-05-09T07:09:21-07:00
Authentication code: 1151

Resizing and Colour change

Post by TheLads »

I am having trouble with resizing and changing the colour of my image.

I have a jpeg and want to change it to the following requirements:
• The image must be a 100x100 PNG
• The background must be transparent (not white or light gray)
• The only color should be #333333
• There should be no white or any other colors in the picture, only transparent and the main color with various levels of alpha
• There should be as little padding as possible


At the moment this is as far as I have gotten:

Code: Select all

"convert.exe" rose.jpeg -gravity center -extent 100x100! -transparent white -fuzz 99.9%% -set filename:f %%t %%[filename:f].png 
-fill and -opaque are not giving me my desired result.
I am using Windows 7 and ImageMagick-7.0.5-Q16
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing and Colour change

Post by snibgo »

TheLads wrote:There should be no white or any other colors in the picture, only transparent and the main color with various levels of alpha
What should determine the level of alpha?
snibgo's IM pages: im.snibgo.com
TheLads
Posts: 3
Joined: 2017-05-09T07:09:21-07:00
Authentication code: 1151

Re: Resizing and Colour change

Post by TheLads »

To be honest, I am unsure what this means. I have been given these requirements without much explanation
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing and Colour change

Post by snibgo »

Creating an image that satisfies the requirements is easy. For example, half the pixels might be #333333 opaque, and the other half fully transparent.

But I suppose the output must be, in some way, dependent on the input.
snibgo's IM pages: im.snibgo.com
TheLads
Posts: 3
Joined: 2017-05-09T07:09:21-07:00
Authentication code: 1151

Re: Resizing and Colour change

Post by TheLads »

https://www.iconfinder.com/icons/298812 ... n#size=128
This is the type of image that would be the input
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Resizing and Colour change

Post by snibgo »

I assume your input is one of the PNG files, and your output should have the same transparency (alpha), but all pixels should have the colour #333333. Windows BAT syntax:

Code: Select all

convert ^
  1494360567_link-external.png ^
  -trim +repage ^
  ( -clone 0 -fill #333333 -colorize 100 ) ^
  ( -clone 0 -alpha extract ) ^
  -delete 0 ^
  -alpha off -compose CopyOpacity -composite ^
  -resize "100x100^!" ^
  out.png
snibgo's IM pages: im.snibgo.com
Post Reply