Something has changed with layers or page?

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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Something has changed with layers or page?

Post by Bonzo »

I have some code that used to work and now it has stopped and I hope somebody can explain the problem.

If you look at this image the part that should be on the right hand side is on the left hand side. Altering the value of page has no effect it is always in the same place.

Image

This seems to be the problem line:

Code: Select all

// Join the images
$cmd = " ( -page -1,0 top_edge.miff -page +0+$alpha center.miff -page +$tweek+0 right_edge.miff -background none -layers merge ) ".
" ( +clone -background black -shadow 80x4+4+4 ) +swap -background none -layers merge +repage ";
This is the full code:

Code: Select all

<?php 
// Input image
$image = '1.jpg'; 

// Resize to a png to stop quality loss
exec("convert $image -thumbnail 500x500 temp.png");

// Get the size of the original image
$size = getimagesize('temp.png');
// The canvas frame edge
$edge = $size[0]*.06;
// New central portion width
$width = $size[0] - ( $edge * 2 );
// New central portion height
$height = $size[1] - ( $edge * 2 );
// Reduction of edge width
$shrink = round(( $edge * 0.6 ), 2);
// Angle of the edge
$angle = 45;
// Change in edge height
// Convert angle to radian > angle in degrees * Pi / 180 
$radian = ( $angle * Pi() ) / 180;
$alpha = round((abs(tan($radian)) * $shrink), 2);
// Edge short side
$short_side = round( ($height - $alpha ), 2);
// Top long side 
$top_long = round($width + $shrink, 2);

// Crop for the edges
$cmd = " temp.png ( -clone 0 -crop {$width}x{$height}+{$edge}+{$edge} +repage -write center.miff +delete )".
" ( -clone 0 -crop {$width}x{$edge}+$edge+0 +repage -write top.miff +delete )".
" -gravity northeast -crop {$edge}x{$height}+0+{$edge} +repage -write right.miff +delete null: ";
exec("convert $cmd ");

// Perspective for the RHS
$cmd = " right.miff -virtual-pixel background -background none ".
" +distort Perspective \"0,0 0,0  $edge,0 $shrink,-$alpha  $edge,$height $shrink,$short_side  0,$height 0,$height\" +repage -trim";
exec("convert $cmd right_edge.miff"); 

// Perspective for the top
$cmd = " top.miff -virtual-pixel background -background none ".
" +distort Perspective \"0,0 $shrink,0  $width,0 $top_long,0  $width,$edge $width,$alpha  0,$edge 0,$alpha\" +repage -trim";
exec("convert $cmd top_edge.miff");

// There was a 1px gap between the RHS and main photo
$tweek = $width-1;

// Join the images
$cmd = " ( -page -1,0 top_edge.miff -page +0+$alpha center.miff -page +$tweek+0 right_edge.miff -background none -layers merge ) ".
" ( +clone -background black -shadow 80x4+4+4 ) +swap -background none -layers merge +repage ";

exec(" convert $cmd canvas1.png");

// Display the final image
echo "<img src=\"canvas1.png\">";

// Alternative style
$cmd = " canvas1.png -virtual-pixel background -background none ".
" +distort Perspective \"0,0 0,-40  962,0 962,0  962,602 962,602  0,602 0,562\" +repage -trim";
exec("convert $cmd canvas2.png");

// Display the final image
echo "<img src=\"canvas2.png\">";

// Cleanup
foreach ( glob("*.miff") as $filename ) { unlink($filename); } 
 ?> 
Version 6.8.5 Q16 on Windows 7
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Something has changed with layers or page?

Post by snibgo »

I don't know what has changed, but see also viewtopic.php?f=1&t=24692
snibgo's IM pages: im.snibgo.com
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Something has changed with layers or page?

Post by Bonzo »

Thanks snibgo, -repage has an effect in that I can move the right side around which I could not do with -page but the placement seems to have nothing to do with the numbers used in -repage.

I will have to have a play around with it later.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Something has changed with layers or page?

Post by Bonzo »

There was a change in 2013 ( 6.8.4-9 Beta ) :
The -page option only affects new images (reference viewtopic.php?f=3&t=23172).
I wonder if that is the problem?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Something has changed with layers or page?

Post by fmw42 »

rather than -page -1,0 should it not be -page -1+0. I was not aware of the comma syntax as being proper.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Something has changed with layers or page?

Post by Bonzo »

rather than -page -1,0 should it not be -page -1+0. I was not aware of the comma syntax as being proper.
Good point fmw42 but changing it to -1+0 had no effect. Perhaps as it was a 0 rather than a larger number it had no effect; although there should have been an error generated or the code should have failed?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Something has changed with layers or page?

Post by fmw42 »

Does this example at http://www.imagemagick.org/Usage/layers/#mosaic still work? You can change the -layers mosaic to -layers merge. This just test -page in a simple environment.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Something has changed with layers or page?

Post by Bonzo »

Good idea fmw42; I had not thought about trying another example.

I used the Windows command line and it did not work, I ended up with just the shading.gif No other images and no background. It looks like something is broken?

Did you try it ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Something has changed with layers or page?

Post by fmw42 »

It failed for me under IM 6.8.8.0 Q16 on Mac OSX. All I got was the last image in the input sequence. I have submitted a bug to the Bugs forum.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Something has changed with layers or page?

Post by Bonzo »

I have submitted a bug to the Bugs forum.
Thanks fmw42; it is good to get a confirmation there is a problem.
Post Reply