3d-buttons with Perl , Dst_In and Fx confusion.

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
zentara

3d-buttons with Perl , Dst_In and Fx confusion.

Post by zentara »

Hi, I was tring to convert the 3d button tutorial at http://www.imagemagick.org/Usage/advanced/#3d-logos-2 to Perl. The commandline code looks like

Code: Select all

#Lets start by again showing the start logo we will be giving a 
#3D look. This is exactly as above, to produce the sample logo.
convert -size 170x100 xc:black \
          -fill white -draw 'circle    50,50  13,50' \
                      -draw 'circle   120,50 157,50' \
                      -draw 'rectangle 50,13 120,87' \
          -fill black -draw 'circle    50,50  25,50' \
                      -draw 'circle   120,50 145,50' \
                      -draw 'rectangle 50,25 120,75' \
          -fill white -draw 'circle    60,50  40,50' \
                      -draw 'circle   110,50 130,50' \
                      -draw 'rectangle 60,30 110,70' \
          -gaussian 1x1 +matte  ant_mask.png

convert ant_mask.png -fill red -draw 'color 0,0 reset' \
          ant_mask.png +matte  -compose CopyOpacity -composite \
          -font Generic.ttf  -pointsize 36  -fill white  -stroke black \
          -gravity Center  -annotate -0 "Ant" \
          ant.png

#I still use a mask for generating the logo, as this is a good way of erasing the area between the central oval and the outer ring of the logo.
#Now lets give it a 3D-look, by using Overlay Highlighting techniques.


##################################
###################################
# my difficulty is here with -fx A  and what Dst_in is
 convert  ant.png  -fx A  +matte -blur 0x6  -shade 110x30  -normalize \
          ant.png  -compose Overlay -composite \
          ant.png  -matte  -compose Dst_In  -composite \
          ant_3D.png
###################################
##################################

#Adding shadows is also easier thanks to the new Shadow Generation operator 
#provided by IM.

convert ant_3D.png \( +clone -background navy -shadow 80x4+6+6 \) +swap \
          -background none  -layers merge +repage ant_3D_shadowed.png
here is my start at a Perl version

Code: Select all

#!/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->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,87');

$image->Draw(primitive=> 'circle',fill=>'black', points=>'50,50  25,50');
$image->Draw(primitive=> 'circle',fill=>'black', points=>'120,50 145,50');
$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,70');

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

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

#I still use a mask for generating the logo, as this is a good way of erasing the area between the central oval and the outer ring of the logo.
#Now lets give it a 3D-look, by using Overlay Highlighting techniques.

################################################
#I'm stuck here with -fx A and Dst_In, I can't figure out the Perl translation 
###############################################

# convert  ant.png  -fx A  +matte -blur 0x6  -shade 110x30  -normalize  ant.png  
#convert -compose Overlay -composite  ant.png  -matte  -compose Dst_In  -composite   #ant_3D.png

$image->Write("ant.png");
__END__


Does anyone know how to finish this 3d thing off?
zentara

Re: 3d-buttons with Perl , Dst_In and Fx confusion.

Post by zentara »

I figured out something close. It was mostly done by hit and miss hacking, so there may be some way to improve it. Here is the script:

Code: Select all

#!/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,87');

$image->Draw(primitive=> 'circle',fill=>'black', points=>'50,50  25,50');
$image->Draw(primitive=> 'circle',fill=>'black', points=>'120,50 145,50');
$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,70');

$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 reser the transparency
$imb->Mogrify('transparent-color' => 'black');

$imb->Write("$0.png");

__END__

Post Reply