Rubblewebs

THESE CODES ARE PROVIDED FOR AN EXAMPLE OF HOW TO USE IMAGEMAGICK WITH PHP. CARE SHOULD BE TAKEN WHEN ACCEPTING USER INPUT.

I TAKE NO RESPONSABILTY FOR ANY PROBLEMS THAT MAY OCCURE WHEN USING ANY OF THIS CODE.

IT IS UP TO YOU TO SECURE THE CODE AND VALIDATE USER INPUT.

Canvas print

A canvas frameless style

Canvas print example
Canvas print example
 
// Input image
$image = $input10;

// 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 = 30;
// 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} -write center.miff +delete )".
" ( -clone 0 -crop {$width}x{$edge}+$edge+0 -write top.miff +delete )".
" -gravity northeast -crop {$edge}x{$height}+0+{$edge} -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 95x10+15+15 ) +swap -background none -layers merge +repage ";
exec(" convert $cmd canvas1.png");

// Display the final image
echo "";

// 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 "";

// Cleanup
foreach ( glob("*.miff") as $filename ) { unlink($filename); }


Back