Page 1 of 1

Beginners question: postioning a image on top of big cirkel at position x,y

Posted: 2016-09-14T02:32:03-07:00
by mc_hendriks
First image is a radial-gradient image (rectangle) (80x80)
Second image is a black circle to be used as a mask (80x80)
Third image is a bigger background image (Big red circle) 200x200

I want to place a gradient (first image) cirkel om de big circle using the mask (second image)
When I use composite to put the image on top of the big circle it 's there but when I try to reposition it using geometry only a part of the gradient circle is left.
Any help in pointing to a solution or documentation or example (would be perfect) is appreciated.

Re: Beginners question: postioning a image on top of big cirkel at position x,y

Posted: 2016-09-14T02:52:33-07:00
by snibgo
You don't show what command you used, so I can't say what is wrong with it.

It also helps if you say what version IM you are using, on what platform.

From your description, I think you want to take the first image, and make transparent all pixels outside the circle in the second image. Then composite that over the third. Something like this (IM v6, Windows BAT syntax):

Code: Select all

convert ^
  first.png ^
  ( second.png -negate ) ^
  -compose CopyOpacity -composite ^
  -geometry +30+40 ^
  third.png ^
  -compose Over -composite ^
  out.png

Re: Beginners question: postioning a image on top of big cirkel at position x,y

Posted: 2016-09-14T03:25:46-07:00
by mc_hendriks
You can see the result at: http://digirent.nl/images/m3.jpg

It is written in perl and my current code is as follows:

#!/usr/bin/perl
#
use strict;
use Image::Magick;
my $x;

# Source, Composite or Overlay image
my $src=Image::Magick->new();
$src->Set(size=>'80x80');
$src->Read('radial-gradient:white-red');
$src->Set(alpha=>'Set');

my $offset="+10+10";
my $offset2="+40+40";

# Circle Mask Image (same size as Destination)
my $circle=Image::Magick->new();
$circle->Set(size=>'100x100');
$circle->Read('xc:black');
$circle->Draw(fill=>'white',primitive=>'circle',points=>'49.5,49.5 10,49.5');

my $texture=Image::Magick->new();
$texture->Read('pattern:checkerboard');

# List of images generated
my $results=Image::Magick->new();

# Working copy of Destination Image
my $clone;
my $img=Image::Magick->new;
$img->Set(size=>'200x200');
$x=$img->ReadImage('xc:none');
warn "$x" if "$x";
my ($center_x,$center_y,$radius)=(100,100,98);
$img->Draw(
fill => 'yellow',
points => "$center_x,$center_y @{[$center_x + $radius]},$center_y",
primitive => 'circle',
);
$img->Label('Yellow circle');
push(@$results, $img);

$clone=$img->Clone();
$clone->Composite(
image=>$src,
mask=>$circle,
compose=>'over',
geometry=>$offset,
);
$clone->Label('Yellow circle with red cirkel');
push(@$results, $clone);

$clone=$img->Clone();
$clone->Composite(
image=>$src,
mask=>$circle,
compose=>'over',
geometry=>$offset2,
);
$clone->Label('Yellow circle with red cirkel');
push(@$results, $clone);


# ----------------------------------------
# Output the changed pixels

# to every image underlay a checkboard pattern
# so as to show if any transparency is present
for my $image ( @$results ) {
$image->Composite(
image=>$texture,
tile=>'True',
compose=>'DstOver',
);
}

my $montage=$results->Montage(
geometry=>'+10+10',
tile=>'4x',
frame=>'6x6+2+2',
shadow=>'True',
);
$montage->Write('show:');
$montage->Write('/var/www/images/m3.jpg');

Re: Beginners question: postioning a image on top of big cirkel at position x,y

Posted: 2016-09-14T03:53:28-07:00
by snibgo
The mask doesn't move with "-geometry".

Re: Beginners question: postioning a image on top of big cirkel at position x,y

Posted: 2016-09-14T04:15:40-07:00
by mc_hendriks
So true, but how can I solve this?

Re: Beginners question: postioning a image on top of big cirkel at position x,y

Posted: 2016-09-14T04:58:34-07:00
by mc_hendriks
found:first create a separate image with the gradient circle and mask and than a composite.