Convert colours

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
raced
Posts: 5
Joined: 2014-05-20T10:13:19-07:00
Authentication code: 6789

Convert colours

Post by raced »

Hi wonder if someone can help.
I am new to this sort of thing !
I have a load of images (templates of mats) The image is all black on a white background.
I want to change the black to red , while leaving the white as is.
I need to do this on mass for 700 images.
I need the file name to remain the same with say _red at end of file name.
I have been sent the following code however file name is changed to test. Can someone help please?
convert *.jpg +level-colors red,white test_red.jpg
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert colours

Post by snibgo »

What is your platform? Windows, Unix, Mac, or what?
snibgo's IM pages: im.snibgo.com
raced
Posts: 5
Joined: 2014-05-20T10:13:19-07:00
Authentication code: 6789

Re: Convert colours

Post by raced »

Hi running on windows 7
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert colours

Post by snibgo »

Code: Select all

for /F "usebackq" %%F in (`dir /b *.jpg`) do convert %%F -fill Red -opaque Black %%~nF_red%%~xF
snibgo's IM pages: im.snibgo.com
raced
Posts: 5
Joined: 2014-05-20T10:13:19-07:00
Authentication code: 6789

Re: Convert colours

Post by raced »

Hi
This doesnt work ? The image remains the same colour ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert colours

Post by snibgo »

Perhaps the images aren't really black. Put an example somewhere like dropbox.com and paste the URL here.
snibgo's IM pages: im.snibgo.com
raced
Posts: 5
Joined: 2014-05-20T10:13:19-07:00
Authentication code: 6789

Re: Convert colours

Post by raced »

http://www.carmats-uk.com/product_images/1268-2OER.jpg
heres a link to one image.
i am using the below code.
This will change the colour from black to red and also resize .
Problem is if it has to do more than one image it then screws.
:copy
ren *.jpg *.JPG

md temp
md webready





:xl
copy *.JPG temp\*.JPG
cd temp



mogrify -resize 500x *.JPG
mogrify -annotate 0,0 '' -font Arial -pointsize 24 xc:grey30 -gravity NorthEast -draw "fill grey70 text 5,5 ''" *
mogrify -annotate 0,0 '' -font Arial -pointsize 24 xc:black -gravity NorthEast -draw "fill black text 6,6 '' text 5,5 '
convert *.jpg +level-colors red,white *.jpg
ren ??????????????????????????????????????????????????.JPG ??????????????????????????????????????????????????_red.jpg


cd ..

deltree temp
pause
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert colours

Post by snibgo »

My command works fine for me. IM v6.8.9-0 on Windows 8.1. If run from a command prompt, change each "%%" to "%".

You said "The image is all black on a white background" but it really has black, white and 4 shades of gray. This isn't surprising, as it is a jpg image. If you have any choice, NEVER use jpg for solid colours.
snibgo's IM pages: im.snibgo.com
raced
Posts: 5
Joined: 2014-05-20T10:13:19-07:00
Authentication code: 6789

Re: Convert colours

Post by raced »

I have removed the % and now nothing happens. I am now totally confused ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert colours

Post by snibgo »

Are you are running a BAT file, or typing the command at the prompt? What exactly is your command?

Nothing happens? No error message?
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert colours

Post by fmw42 »

What version of Imagemagick are you using? Perhaps you need to ugrade

You cannot use multiple inputs and make multiple outputs using convert.


Either of these work for me on my Mac (unix syntax). The first, however, puts a period before _red.jpg

The input data is in test1 and the results are put into test2 (test2 must exist)

Code: Select all

cd desktop/test1
mogrify -path /Users/fred/desktop/test2 -format _red.jpg +level-colors red,white "*.jpg"
This has the input data in test1 and puts the result in test1

Code: Select all

for img in $(ls); do
convert $img +level-colors red,white ${img}_red.jpg
done

This has the input data in test1 and puts the result in test2

Code: Select all

for img in $(ls); do
convert $img +level-colors red,white ../test2/${img}_red.jpg
done
Sorry I do not know the windows syntax.
Post Reply