Page 1 of 1

Set Image Border

Posted: 2014-06-02T01:49:20-07:00
by pranav
Hi All,
I have tree sample images in landscape and portrait format, Now i want to set dynamically set border color on its edges, I am little bit slow in imagemagick , so not able to perform this.
Can any one look into this.

My Sample code and sample images can be downloaded from below path.

https://www.dropbox.com/sh/m2w7qczkfx0m ... F9wsRwAxPa


Thanks in Advance.

Re: Set Image Border

Posted: 2014-06-02T05:03:17-07:00
by Bonzo
I am not sure what you mean about "set dynamically set border color ".

Can you show what you want with some example images created in another program?

Re: Set Image Border

Posted: 2014-06-02T05:21:57-07:00
by pranav
Hi Bonzo, Thanks for your reply, I have uploaded output.zip onto same dropbox url,

I mean by dynamic border is when i am trying to create 3d image it leaves some gap between image and edges,

But when you put the images one by one in script $image variable, you will get the output images, same those i have uploaded in output.zip file

Re: Set Image Border

Posted: 2014-06-02T06:14:24-07:00
by snibgo
I don't so PHP so can't test, but I notice that you don't "+repage" after the crops. That may be correct, or may cause problems.

Re: Set Image Border

Posted: 2014-06-02T06:56:34-07:00
by pranav
Nop, +repage is not working with the same, have tried with the same before and now also........... :)

Re: Set Image Border

Posted: 2014-06-02T10:29:31-07:00
by Bonzo
An example of your expected result is always useful, try this:

Code: Select all

<?php  
// Input image 
$image = 'Chrysanthemum.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]; 
// New central portion height 
$height = $size[1]; 
// 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); 

// Resize the center
exec("convert $image -thumbnail 500x500 center.png"); 

// Crop for the edges 
$cmd = " temp.png ( -clone 0 -crop {$width}x{$edge}+0+0 -flip -fill #FFC0CB -colorize 100% -write top.png +delete )". 
" -gravity northeast -crop {$edge}x{$height}+0+0 -flop -fill #E75480 -colorize 100%  -write right.png +delete null: "; 
exec("convert $cmd "); 

// Perspective for the RHS 
$cmd = " right.png -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.png"); 

// Perspective for the top 
$cmd = " top.png -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.png"); 

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

// Join the images 
$cmd = " ( -page -1,0 top_edge.png -page +0+$alpha center.png -page +$tweek+0 right_edge.png -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 "<img src=\"canvas1.png\">";
?>
Notice the -fill and -colorize added to the // Crop for the edges section

Re: Set Image Border

Posted: 2014-06-03T02:09:10-07:00
by pranav
Hey Bonzo,
That was amazing, now I got where i was doing mistake, there was wrong calculation for image edge sizes, for height and width, and the alternative you have given for -fill command is very qualifies logic, we can use it in the alternate of border color, i am right i think.

You gave a amazing help and guidance. Thanks a lot and keep it up with the forum. See ya in next lesson and learning in imagick..... :D

Cheers..

Thank again for your time and guidance....