Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Transparent 3d logo/button with ImageMagick

by zentara (Archbishop)
on Oct 01, 2008 at 19:05 UTC ( [id://714873]=sourcecode: print w/replies, xml ) Need Help??
Category: GUI Programming
Author/Contact Info zentara of perlmonks
Description: I liked the 3b button/logo shown at better 3d logos but had great difficulty translating the shell commands to Perl. Here is what I came up with, it works well, and it's quite possible it can be streamlined....let me know if you see code bloat. Open it in Gimp to see it's transparency.
#!/usr/bin/perl -w
use strict;
use Image::Magick;

my $image = Image::Magick->new;
$image->Set(size=>'170x100');
my $rc = $image->Read("xc:black");

$image->Set(alpha => 'transparent');
$image->Set('transparent-color' => 'black');

$image->Draw(primitive=> 'circle',fill=>'red', points=>'50,50  13,50')
+;
$image->Draw(primitive=> 'circle',fill=>'red', points=>'120,50 157,50'
+);
$image->Draw(primitive=> 'rectangle',fill=>'red', points=>'50,13 120,8
+7');

$image->Draw(primitive=> 'circle',fill=>'black', points=>'50,50  25,50
+');
$image->Draw(primitive=> 'circle',fill=>'black', points=>'120,50 145,5
+0');
$image->Draw(primitive=> 'rectangle',fill=>'black', points=>'50,25 120
+,75');

$image->Draw(primitive=> 'circle',fill=>'red', points=>'60,50  40,50')
+;
$image->Draw(primitive=> 'circle',fill=>'red', points=>'110,50 130,50'
+);
$image->Draw(primitive=> 'rectangle',fill=>'red', points=>'60,30 110,7
+0');

$image->Set(matte=>1);
$image->Set(gaussian=>'1x1');

#$image->Write("pant_mask.png");
# mogrify will get the inner black circle and set it transparent
$image->Mogrify('transparent-color' => 'black');
#$image->Write("pant.png");

# make a clone to blur
my $imb = $image->Clone();
$imb->Blur(radius=>0,sigma=>6);
$imb->Shade(geometry=>'110x30',gray=>1);
$imb->Normalize(channel=>'All');
$imb->Set(matte=>0);
#$imb->Write("pantblur.png");

# do 2 composites to simulate the 3d effect
$rc = $imb->Composite(gravity => "Center", 
    compose=>'Overlay',
     image => $image,
      );
warn $rc if $rc;
#$imb->Write("pant_z3d.png");

$rc = $imb->Composite(gravity => "Center", 
    compose=>'DstIn' ,
    image => $image);

# add your text
$imb->Annotate(
        pointsize=>36, 
        text=>'Ant', 
        stroke => 'black', 
        fill => 'white', 
        gravity => 'center',
        x=> 0, # offsets
        y=> 0,  # offsets
);

# need to reset the transparency
$imb->Mogrify('transparent-color' => 'black');
$imb->Write("$0.png");

__END__

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://714873]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-03-28 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found