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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
|
11-17-2007, 03:43 AM
|
#1
|
Senior Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,298
Rep:
|
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.
|
|
|
11-17-2007, 06:54 AM
|
#2
|
LQ Guru
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,196
|
Have you checked ImageMagick?
jlinkels
|
|
|
11-17-2007, 07:40 AM
|
#3
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
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!
|
|
|
11-17-2007, 09:19 AM
|
#4
|
Senior Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,298
Original Poster
Rep:
|
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.
|
|
|
11-17-2007, 09:31 AM
|
#5
|
Member
Registered: Nov 2007
Posts: 113
Rep:
|
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?
|
|
|
11-17-2007, 10:11 AM
|
#6
|
Senior Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,298
Original Poster
Rep:
|
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.
|
|
|
11-17-2007, 10:22 AM
|
#7
|
Member
Registered: Nov 2007
Posts: 113
Rep:
|
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?
|
|
|
11-17-2007, 06:15 PM
|
#8
|
Member
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195
Rep:
|
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.
|
|
|
11-17-2007, 07:16 PM
|
#9
|
Member
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195
Rep:
|
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.
|
|
|
11-18-2007, 01:50 AM
|
#10
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
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.
|
|
|
11-18-2007, 07:26 AM
|
#11
|
Senior Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,298
Original Poster
Rep:
|
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.
|
|
|
11-18-2007, 09:55 AM
|
#12
|
Member
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195
Rep:
|
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
|
|
|
11-18-2007, 10:01 AM
|
#13
|
Member
Registered: Nov 2007
Posts: 113
Rep:
|
could even create your own arrow data array and rotate that to any arbitrary radian, then place it into any sized and coloured image...
|
|
|
11-18-2007, 11:00 AM
|
#14
|
Senior Member
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 11
Posts: 1,298
Original Poster
Rep:
|
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.
|
|
|
11-18-2007, 12:10 PM
|
#15
|
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
|
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:
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.
|
|
|
All times are GMT -5. The time now is 01:09 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|