Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-07-2015, 08:34 AM   #1
Registered: Sep 2005
Posts: 201

Rep: Reputation: 19
Change a color in a png with imagemagick convert

I have two png images (a sort of fireframe section pictures). I want to merge them together over each other - this I already managed with transparency option and all. I only have one remaining problem - since both pictures feature a fireframe in the same color it would be nice to change that particular color of the second image to something else. How can I change color "red" to "blue"

I think this should be possible without editing the whole palette but I have not been able to find how.

I want to do this on command line so I found that convert is the most promising one, but I got stuck with this last issue?
Old 10-07-2015, 09:55 PM   #2
John VV
LQ Muse
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,602

Rep: Reputation: 2648Reputation: 2648Reputation: 2648Reputation: 2648Reputation: 2648Reputation: 2648Reputation: 2648Reputation: 2648Reputation: 2648Reputation: 2648Reputation: 2648
you really need to read the website
or the imagemagick manual

a lot of things can be done with "display"

have you read the output of
convert --help
personally i would just change the colorspace to HSV and move the hugh value then move back into rgb

also for 99.999 of things i moved to using G'Mic" image lib a few years back

I now only use imagemagick for the Q32 custom build i have for using in the math program Octave ( matlab)


for switching the red and blue

a rgb image is a 3 layer image
flip flop layer 1 and 3
this is easy to do using Nip2 ( and the vips image lib) this also replaced my use of imagemagick years and years ago
Old 10-08-2015, 12:56 AM   #3
Registered: Sep 2005
Posts: 201

Original Poster
Rep: Reputation: 19
I looked at convert --help already before posting. I am sure lots of things can be done with display.
I am missing practical examples. Now I was able to accomplish what I wanted with mogrify
mogrify -path tmp_2 -format png -fill blue -opaque red -alpha set -transparent white tmp_2/*.png
works pretty much as I wanted.

I have two image sequences and I want to merge them. For merging I use convert:

mkdir tmp_1
mkdir tmp_2
mkdir tmp_3
ffmpeg -i $1 -f image2 tmp_1/video_1_05d.png
ffmpeg -i $2 -f image2 tmp_2/video_2_%05d.png
mogrify -path tmp_1 -format png -alpha set -transparent white tmp_1/*.png
mogrify -path tmp_2 -format png -fill blue -opaque red -alpha set -transparent white tmp_2/*.png
foreach i ( `ls tmp_1/* | sed "s/.*video_1_//" | sed "s/\.png//"` )
        convert -composite tmp_2/video_2_$i.png tmp_1/video_1_$i.png tmp_3/video_3_$i.png
mogrify -path tmp_3 -format png -background white -alpha Background tmp_3/*.png
ffmpeg -i tmp_3/video_3_%05d.png -an -vcodec mjpeg combined.avi
This works pretty well and fast, except for the foreach loop which is the most time
consuming bit. I just could not figure it out if I can accomplish that with wildcards.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a palette app with a movable glass to convert text color code into a color? Xl1NntniNH7F Linux - General 2 08-08-2011 01:11 AM
(imagemagick)why this command can not compress png image... kingliang123 Linux - Software 4 01-12-2011 08:45 PM
[SOLVED] Using convert from imagemagick package to convert multiple jpg files janis_169 Linux - Newbie 5 07-18-2010 04:22 PM
imagemagick problem: height-and-width not deterministic when I crop an png file. centguy Linux - Software 2 09-09-2009 05:31 AM
ImageMagick, change color Kocil Linux - Software 0 10-14-2003 10:04 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:52 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration