LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-17-2007, 03:43 AM   #1
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,298

Rep: Reputation: 52
image manipulation by script


I have 1152 short .png files of about 150 bytes each. These files are images of the same arrow pointing in 8 possible directions and in some 144 different colours. The problem is that the background of these images is always white and I'd like to make it match a colour from the main picture in which they are placed.

Note these so-called main pictures are created by HTML and CSS using the colour numbers (#66ff33 etc).

Is it possible at all to write a script that does that?

Thank you for your help.
 
Old 11-17-2007, 06:54 AM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196

Rep: Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044Reputation: 1044
Have you checked ImageMagick?

jlinkels
 
Old 11-17-2007, 07:40 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Hi, rblampain. Is the color fixed (predetermined) or have to be retrieved dynamically from the main picture? I feel like I already saw these 1152 pictures!
 
Old 11-17-2007, 09:19 AM   #4
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,298

Original Poster
Rep: Reputation: 52
Thank you both for your answers.
To colucix, yes, you kindly created these pictures some months ago because I have no experience with Gimp etc, they are working well but the white background of the image gives, in my view, an unfinished appearance because it is the only common feature in all the "pictures".
Each of these 1152 arrows is a file whose filename is the colour number, a BASIC program creates the main HTML code and calls the correct "arrow". To change the background colour and create appropriate arrows with suitable background and foreground colours would have needed too many files (1152 * 144) to download each time someone visits the site, hence my question.

To answer your question, yes the color is fixed and it is white.

To jlinkels, no, I had never heard of it but I will have a look at it.
 
Old 11-17-2007, 09:31 AM   #5
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Rep: Reputation: 16
You could also look at the GD Library http://www.boutell.com/gd/, not sure about how your basic program generates the html, personally I use php and GD is now included so it's a breeze to manipulate images, and i'm not sure why you don't just have 8 images and adjust accordingly, other than because of generation time and resource, but if your going to consider doing 1152 * 114 separate images, I gotta ask why not a transparent background and a colour mask for the foreground?
 
Old 11-17-2007, 10:11 AM   #6
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,298

Original Poster
Rep: Reputation: 52
Thank you to brazilnut.
I was and still am very ignorant of what can be done. The possibility of using only 8 images is a revelation to me. It is also the solution, I just have to find out how. I have a basic and rusty experience of PHP, could you give me a few hints?

My old method goes like this, the BASIC program selects at random a number of colours used for various displays, one is used also for the foreground colour of the "arrow" (by including the appropriate arrow file of the same colour) and another could be used for the background colour of the "arrow". This random selection gives a 6 digits number in the form "#66ff33". This BASIC program can be rewritten to also include some PHP code. The result, with some text, becomes a HTML/PHP script that is "included" into the pages of a site.

Last edited by rblampain; 11-17-2007 at 10:19 AM.
 
Old 11-17-2007, 10:22 AM   #7
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Rep: Reputation: 16
Just so that I understand, are these images being generated before being uploaded to the server, or upon request from the server?

Also when you say BASIC, I now assume you don't mean VB because of your 'Distribution' listing?
 
Old 11-17-2007, 06:15 PM   #8
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
As I understand it Coucix has gone to some lengths previously to produce arrows for you and Jinkels gave you the tip to look at Imagemagick. In the following the first convert (an imagemagick command) is merely to create a gif or png image with a white background for you to see before making the white background transparent. The documentation says -transparency, but in my version of imagemagick 6.2.5-1620 which is part of SUSE 10.1 it's -transparent.

Code:
#!/bin/sh
convert -density 90 -pointsize 72 label:FooBar example.png
convert -transparent white example.png output.gif
imagemagick transparency

You should have no problem changing your 8 arrows to have transparent backgrounds and i'm sure that Coucix will have given them filenames that are eminently processable in a bash loop.
I think that you will need to settle for a gif if you want the transparency, but that second line could have read example.png example.png to do a rewrrite in place if you felf you needed it.
If you have anything to do with image manipulation and scripts then don't learn imagemagick, there is just too much, but make yourself familiar and learn to use what you need.

I bet Jinkels just loves IM. Sigh, it is even available for that OTHER OS.

Google, imagemagick and imagination are your friends.

Don't forget to let us all know how you get on.
How about a link to your arrows (only 8 of them).

PAix

Last edited by PAix; 11-17-2007 at 06:16 PM.
 
Old 11-17-2007, 07:16 PM   #9
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
First you get yourself an image called kangaroo.png (or change the name) that is black with a white background, preferably square
Code:
#!/bin/sh

for colour in $(echo red green yellow black blue)
do
   for angle in $(echo 0 45 90 135 180 225 270 315)
   do
      echo $colour $angle

      convert -transparent white -fill $colour -opaque black \
              -rotate $angle kangaroo.png output$colour$angle.gif
   done
done
Have fun, it doesn't have to be a kangaroo of course, an arrow is quite acceptable I'm sure.

PAix
PS forget the link to your arrows - no offence Coucix, I'm sure that they were lovely.
PPS Ok the resizing of the image due to the diagonals 45 degrees etc have allowed me to make a right horlicks of those images. a bit of a smart cropping is needed - I'll be back, then i'll whack it into a tacky animation to show I have no tast as well as being slightly stupid on occasions.

Last edited by PAix; 11-17-2007 at 09:23 PM.
 
Old 11-18-2007, 01:50 AM   #10
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Why not make the background transparent? When the image is displayed, whatever is behind it will show through the transparent background areas? This can be done with Imagemagick, left as an exercise for the reader.... (don't know exactly off the top of my head). Can also be done with the Gimp, or proably just about any image manipulation software.
--- rod.
 
Old 11-18-2007, 07:26 AM   #11
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,298

Original Poster
Rep: Reputation: 52
To answer brazilnut:
The BASIC program is written in YABASIC which is available with Debian distros. There is nothing built dynamically, the selections of arrows is made at the time the containing HTML/PHP script is written, by this BASIC program which selects the colours and, consequently the fg colours of the arrows.

To all:
One confusion I had, these 1152 images do not need to be downloaded by the visitor because the HTML/PHP document that uses them is assembled by PHP before download by the visitor.

It seems the suggestions to make the background transparent is the most practical with my level of experience. It is good to know the whole thing can be based on 8 images only but I think I may need to much help to achieve this.

I will try transparency and theNbomr's script and I will let everybody know the results.

Thank you very much for your advices.
 
Old 11-18-2007, 09:55 AM   #12
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
In fact, you can base it on two original images. Two arrows that you can each rotate 90 degrees. I overlooked the effect of rotating an image by 45 degrees which changed the size and complicates life unduly. so if you make two images one vertical and one pointing at 45 degrees. both having the same SQUARE size, then you can rotate each in increments of 90 degrees, suffering no size inflation problems (easy out for me) and life is dead simple. You can either produce and store the images or store the two and generate what you need by the specifying angle and colour to meet your immediate requirements.

IM is certainly worth getting to know. Just bone up on the bits you need to solve your immediate needs, such as titling etc.

PAix
 
Old 11-18-2007, 10:01 AM   #13
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Rep: Reputation: 16
could even create your own arrow data array and rotate that to any arbitrary radian, then place it into any sized and coloured image...
 
Old 11-18-2007, 11:00 AM   #14
rblampain
Senior Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,298

Original Poster
Rep: Reputation: 52
Thank you for the advices but I have no time to learn new software, especially because this is a one-off job involving graphics for an organization run by volunteers.

I followed a couple of links from the net to move white parts of an image to transparency (http://geekswithblogs.net/timh/archi.../20/72797.aspx)
and I have barely managed, using the mouse to get one arrow transparent with gimp although I lost the fg colour, I have also run PAix's script after removing the 45 degrees rotations and inserting the name of a test file but, not understanding the script, this was bound to fail, and it did.

So one question remains now: how can I add transparency to those images with a script using a file containing 1152 filenames as an input? I am willing to learn Bash though.

I have installed "Imagemagick" with "synaptic" and although it went OK I can't find it, nor start it.

Last edited by rblampain; 11-18-2007 at 11:01 AM.
 
Old 11-18-2007, 12:10 PM   #15
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Imagemagick, when installed, is a whole collection of utilities. The one you want in this case will be 'convert'.

I have just tried this, so I could explain it to you. I first created an image with the Gimp, which is an arrow, green with a black border on a field of white, saved as arrow.png. I use imagemagick to display it:
Code:
display arrow.png
I see just what I described above. Next:
Code:
convert arrow.png -transparent white arrowTransparent.png
display arrowTransparent.png
I see the same figure, but the white background is now transparent.


--- rod.

Last edited by theNbomr; 11-18-2007 at 12:27 PM.
 
  


Reply


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
Resource for image manipulation surfer41 Programming 1 05-23-2007 08:31 PM
Best image manipulation library? dezert_fox Linux - Software 1 07-26-2006 03:15 AM
Image manipulation library for console? Shioni Programming 12 03-28-2006 09:22 AM
Batch image manipulation elfoozo Linux - Software 5 06-03-2005 07:22 PM
[C/C++] Image manipulation Cornholio Programming 2 03-06-2005 12:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:09 PM.

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