I am new to Imagemagick, just installed it yesterday and I find it a little bit complicated.
I have cut with Gimp a frame into 8 pieces :
- top-left.png
- top-middle.png
- top-right.png
- right-middle.png
- bottom-right.png
- bottom-middle.png
- bottom-left.png
- left-middle.png
You may find them here to test the code I share: http://www.cjoint.com/doc/17_04/GDtsbdUYPze_frames.zip
The source image:
The result of my Imagemagick script:
It's working fine, but I generate 18 images to achieve this result, the PHP Code with exe() :
Code: Select all
$timeStart = microtime(TRUE);
$maxSize = 1000;
$imageSrc = 'images/image1.jpg';
$sizeTopLeft = getimagesize('frames/top-left.png');
$sizeTopRight = getimagesize('frames/top-right.png');
$sizeBottomLeft = getimagesize('frames/bottom-left.png');
$sizeBottomRight = getimagesize('frames/bottom-right.png');
$sizeImage = getimagesize($imageSrc);
if($sizeImage[0] >= $sizeImage[1]) {
$widthFramedImage = $maxSize;
$widthImage = ($widthFramedImage - $sizeTopLeft[0] - $sizeTopRight[0]);
$heightImage = intval(($widthImage * $sizeImage[1]) / $sizeImage[0]);
$heightFramedImage = $heightImage + $sizeTopLeft[1] + $sizeBottomLeft[1];
} else {
$heightFramedImage = $maxSize;
$heightImage = ($heightFramedImage - $sizeTopLeft[1] - $sizeTopRight[1]) + 1;
$widthImage = intval(($heightImage * $sizeImage[0]) / $sizeImage[1]);
$widthFramedImage = $widthImage + $sizeTopLeft[0] + $sizeBottomLeft[0];
}
echo "$widthFramedImage / $heightFramedImage <hr>";
exec("convert $imageSrc -resize ".$widthImage."x".$heightImage." target-image.png");
echo '<img src="target-image.png"><hr>';
exec("convert -size ".$widthFramedImage."x".$heightFramedImage." xc:white 1.png");
/**
* Add top Left
*/
exec("convert 1.png frames/top-left.png -geometry +0+0 -composite 2.png");
echo '<img src="2.png"><hr>';
/**
* Add top Right
*/
$x = $widthFramedImage - $sizeTopRight[0];
exec("convert 2.png frames/top-right.png -geometry +$x+0 -composite 3.png");
echo '<img src="3.png"><hr>';
/**
* Add Bottom Right
*/
$x = $widthFramedImage - $sizeBottomRight[0];
$y = $heightFramedImage - $sizeBottomRight[1];
exec("convert 3.png frames/bottom-right.png -geometry +$x+$y -composite 4.png");
echo '<img src="4.png"><hr>';
/**
* Add Bottom Left
*/
$y = $heightFramedImage - $sizeBottomLeft[1];
exec("convert 4.png frames/bottom-left.png -geometry +0+$y -composite 5.png");
echo '<img src="5.png"><hr>';
/**
* Pattern Right with tile:
*/
$heightPattern = $heightFramedImage - ($sizeTopRight[1] + $sizeBottomRight[1]);
$x = $widthFramedImage - $sizeTopRight[0];
$y = $sizeTopRight[1];
exec("convert -size ".$sizeTopRight[0]."x".$heightPattern." tile:frames/right-middle.png pattern-right.png");
echo '<img src="pattern-right.png"><hr>';
exec("convert 5.png pattern-right.png -geometry +$x+$y -composite 6.png");
echo '<img src="6.png"><hr>';
/**
* Pattern Bottom with tile:
*/
$widthPattern = $widthFramedImage - ($sizeBottomLeft[0] + $sizeBottomRight[0]);
$y = $heightFramedImage - ($sizeBottomLeft[1]);
exec("convert -size ".$widthPattern."x".$sizeBottomLeft[1]." tile:frames/bottom-middle.png 0x0 pattern-bottom.png");
echo '<img src="pattern-bottom.png"><hr>';
exec("convert 6.png pattern-bottom.png -geometry +$sizeBottomLeft[0]+$y -composite 7.png");
echo '<img src="7.png"><hr>';
/**
* Adding the picture inside the Frame before the shadows...
*/
$x = $sizeTopLeft[0];
$y = $sizeTopLeft[1];
exec("convert 7.png target-image.png -geometry +$x+$y -composite 8.png");
echo '<img src="8.png"><hr>';
/**
* Pattern Top with Shadow using tile:
*/
$widthPattern = $widthFramedImage - ($sizeTopLeft[0] + $sizeTopRight[0]);
exec("convert -size ".$widthPattern."x".$sizeTopLeft[1]." tile:frames/top-middle.png pattern-top.png");
exec("convert pattern-top.png ( -clone 0 -background black -shadow 40x6+0+15 ) -reverse -background none -layers merge +repage pattern-top-shadow.png");
$sizePatternTop = getimagesize("pattern-top.png");
$sizePatternTopShadow = getimagesize("pattern-top-shadow.png");
$widthCrop = intval( ($sizePatternTopShadow[0] - $sizePatternTop[0])/2);
exec("convert pattern-top-shadow.png -crop ".$sizePatternTop[0]."x".$sizePatternTopShadow[1]."+$widthCrop+0 pattern-top-shadow-cropped.png");
echo "Pattern Sizes/Pattern Shadow Sizes : <br>$sizePatternTop[0] / $sizePatternTopShadow[0] <br> $sizePatternTop[1] / $sizePatternTopShadow[1] <br>";
echo '<img src="pattern-top-shadow-cropped.png"><hr>';
exec("convert 8.png pattern-top-shadow-cropped.png -geometry +$sizeTopLeft[0]+0 -composite 9.png");
echo '<img src="9.png"><hr>';
/**
* Pattern Left with Shadow using tile:
*/
$heightPattern = $heightFramedImage - ($sizeTopLeft[1] + $sizeBottomLeft[1]);
$y = $sizeTopRight[1];
exec("convert -size ".$sizeTopRight[0]."x".$heightPattern." tile:frames/left-middle.png pattern-left.png");
exec("convert pattern-left.png ( -clone 0 -background black -shadow 40x6+15+0 ) -reverse -background none -layers merge +repage pattern-left-shadow.png");
$sizePatternLeft = getimagesize("pattern-left.png");
$sizePatternLeftShadow = getimagesize("pattern-left-shadow.png");
$heightCrop = intval( ($sizePatternLeftShadow[1] - $sizePatternLeft[1])/2);
exec("convert pattern-left-shadow.png -crop ".$sizePatternLeftShadow[0]."x".$sizePatternLeft[1]."+0+$heightCrop pattern-left-shadow-cropped.png");
echo '<img src="pattern-left-shadow.png"><hr>';
exec("convert 9.png pattern-left-shadow-cropped.png -geometry +0+$y -composite 10.jpg");
echo '<img src="10.jpg" style="margin:50px; box-shadow: 8px 8px 20px #404040;"><hr>';
$timeEnd = microtime(TRUE);
$timeTaken = $timeEnd - $timeStart;
$time_taken = round($timeTaken,5);
echo 'Image generated in '.$timeTaken.' seconds.';
You may find test images I used here: http://www.cjoint.com/doc/17_04/GDtsneVNIAe_images.zip
Many thanks