how to use the top composed img size as the result img size?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

how to use the top composed img size as the result img size?

Post by linjuming »

source pattern image:
Image

description:
Image

my code:

Code: Select all

<?php

$gb_pattern="pattern.png ";
$im=new imagick($gb_pattern);
$pattern_geo=$im->getimagegeometry();
$width=$pattern_geo["width"];
$height=$pattern_geo["height"];

$cmd =	"convert " .
		"-size {$width}x$height xc:#D18521 " .
		"( tile:$gb_pattern  -alpha set -channel A -evaluate set 50% ) -compose overlay -composite " .
		"page.png";

exec($cmd);

echo "<img src='pattern.png'/>";
echo "<br><br>";
echo "<img src='page.png'/>";

?>
1,use pure color to be background;
2,top img is the pattern.png ,use "-compose overlay" method;

can my code be any shorter? it seems a little long. any option using the top image's width and height as the composed img's?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: how to use the top composed img size as the result img s

Post by anthony »

For "overlay" NO --- However Overlay is not designed to be used with transparency any way, so I have no idea what you are trying to do !!!!!



for "over" composition -- YES There are a number of options...

"convert " .
"-size {$width}x$height xc:#D18521 " .
"tile:$gb_pattern -define compose:args=50 -compose dissolve -composite " .
"page.png";

You are really doing a blending see.. http://www.imagemagick.org/Usage/compose/#blend

The disolve does the equivlent of a 50% transparency on the source image.

Actually is can also adjust the destination image too!


For opaque images (such as you have) you can use blend instead of dissolve, as in that case the results are the same (by the operators own definition). they only differ when transparency is involved in at least one of the images.


However as you are blending/dissolving a solid color you can also use -colorize

convert -size {$width}x$height tile:$gb_pattern -fill '#D18521' -colorize 50% page.png

See Colorize
http://www.imagemagick.org/Usage/color_mods/#colorize
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
linjuming
Posts: 122
Joined: 2011-01-25T00:09:50-07:00
Authentication code: 8675308

Re: how to use the top composed img size as the result img s

Post by linjuming »

great ,that helps much ! thanks !
Post Reply