[ubuntu-uk] bulk graphics processing problem

John Levin technolalia at gmail.com
Fri Mar 25 16:11:47 UTC 2011


On 19/03/2011 23:10, Avi wrote:
> On Sat, 19 Mar 2011 15:01:05 +0000
> John Levin<technolalia at gmail.com>  wrote:
>
>> hi all,
>>
>> I need several series of numbered icons, from about 1 to 111 in
>> different colours. There must be a way of automating this through the
>> command line using imagemagick, but I haven't found a way of doing
>> so, and my google - fu is giving very poor returns today. Any one got
>> any ideas?
>
> With no testing whatsoever, and only a passing (but google-enhanced)
> familiarity with imagemagick, this is how I'd do it in Perl.
>
> Basically, define an array of acceptable colours, then iterate through
> the numbers 1 through 111. For each, pick two different colours at
> random to use as foreground and background colours and create an icon.
>
> I don't even know if the imagemagick command really does what I want it
> to - I got it from [0] - and this could be done in any language, I just
> can't remember how to do arrays in bash.
>
>
> #! /usr/bin/perl
>
> my @colours=("red","green","blue","orange");
>
> for (my $i = 1; $i<= 111; $i++) {
>
> 	# Pick a random colour for fg and bg out of the array:
> 	my $fgcolour = $colours(int rand($#colours +1));
> 	my $bgcolour = $colours(int rand($#colours +1));
>
> 	# Check they're not equal
> 	while ($bgcolour == $fgoclour){
> 		$bgcolour = $colours(int rand($#colours +1));
> 	}
>
> 	# Concoct a command
> 	my $cmd="convert -size 16x16 xc:$colour ";
> 	$cmd .= "-pointsize 8 -fill green ";
> 	$cmd .= "-stroke black ";
> 	$cmd .= " -draw 'text 10,55 \"$i\"' ";
> 	$cmd .= "icon_$i.jpg ";
>
> 	# Run it
> 	`$cmd`;
> }
>
>
> [0] http://www.imagemagick.org/Usage/draw/#specifics


Avi, many many thanks!

The code above doesn't work straight off, but I've managed to get it 
running (I don't know perl) and now have a working script. Am doing some 
tweaking and will post my version up when that's done.

John

-- 
John Levin
http://www.anterotesis.com
johnlevin at joindiaspora.com
http://twitter.com/anterotesis




More information about the ubuntu-uk mailing list