Canvas wrap transformation

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?".
dlo194
Posts: 1
Joined: 2012-08-24T02:28:13-07:00
Authentication code: 67789

Re: Canvas wrap transformation

Post by dlo194 »

I have had to do something very similar to this.

Code: Select all

iWidth = image width
iHeight = image height
adjX = (iWidth * 0.2) / 2      // Scaling factor that works for me
adjY = iHeight * 0.1
frameWidth = 15       // width of the frame side

convert input.jpg
-virtual-pixel white -distort Perspective
                "0,0," & adjX & ",0" 
                ",0," & iHeight & "," & adjX & "," & iHeight 
                "," & iWidth & ",0," & iWidth - adjX & "," & adjY 
                "," & iWidth & "," & iHeight & "," & iWidth - adjX & "," & iHeight - adjY 
( +clone -crop 1x" & iHeight & "+" & adjX & "+0"
-fill black -colorize 40% -write mpr:line +delete )
-draw image over " & adjX - frameWidth & ",0 " & frameWidth & "," & iHeight & " 'mpr:line'"
( +clone -crop frameWidth & "x" & iHeight & "+" & adjX - frameWidth & "+0"
 -virtual-pixel white -distort Perspective
                "0,0,0,10,"
                "0," & iHeight & ",0," & iHeight - 10 & ","
                frameWidth & ",0," & frameWidth & ",0,"
                frameWidth & "," & iHeight & "," & frameWidth & "," & iHeight
 -write mpr:side +delete )
 -draw image over " & adjX - frameWidth & ",0 " & frameWidth & "," & iHeight & " 'mpr:side'"
output.jpg
Im sure this can be done more efficiently but it works for me.
The above code was originally VB.net so you will need to replace how the widths and heights are inserted to suit your language.
Instead of wrapping the image to make the left side panel it copies the first column of pixels and stretches it.
Also I have not highlighted the joins I have instead darkened the side panel.
Resultant image:
Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Canvas wrap transformation

Post by anthony »

Very nice. The darkening does the job very well.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
chrisr
Posts: 1
Joined: 2012-12-20T08:26:43-07:00
Authentication code: 6789

Re: Canvas wrap transformation

Post by chrisr »

Hi, what is the exact coordinates for first message image.
(bride picture)

I will be very thankful that could give accurate results.
Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Canvas wrap transformation

Post by fmw42 »

lenscape wrote:I'm trying to figure out how to use ImageMagick to transform an image so it looks like it's a canvas wrap, seen from off-centre, slightly from one side.

This is a pretty good example of what the finished image might look like: Image.
Dale,

Would you please repost or fix the link to the example image. Thanks. I am working on a script to do something like this and would like to review your example again.

Fred
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Canvas wrap transformation

Post by fmw42 »

Dale,

Thanks for reposting that.

I have now uploaded a script, 3Dcover, to my web site that creates something like this. See my link below. It allows a white line to be drawn along the seams, allows a vignette on the front face, allows either a backdrop shadow or a ground shadow to be added. It can be rotated with positive or negative angles about the Y axis along the seam. The perspective effect (exaggeration) may also be changed. The width of the side is also adjustable.

Fred
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Canvas wrap transformation

Post by anthony »

Note Fred.. Take a closer look at the line along the edge. It is brighter in the center than at the top and bottom. :-) that is it is a parabolic gradient (white and transparency) rather than simply a vertical line.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Canvas wrap transformation

Post by fmw42 »

anthony wrote:Note Fred.. Take a closer look at the line along the edge. It is brighter in the center than at the top and bottom. :-) that is it is a parabolic gradient (white and transparency) rather than simply a vertical line.
It is simply a line drawn (-strokewidth=2) with a transparent -stroke graylevel, in this case white, ie gray(100%,0.2). So perhaps the transparency gives it that effect.
yazilim
Posts: 6
Joined: 2013-02-07T23:42:45-07:00
Authentication code: 6789

Re: Canvas wrap transformation

Post by yazilim »

hello
i'm use to php canvas print screen =>
ImageImage

use code =>

Code: Select all

// Input image
$image = 'resim.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 = 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);

/*
echo "
edge = $edge<br>
width = $width<br>
height = $height<br>
shrink = $shrink<br>
Angle = $angle<br>
Alpha = $alpha<br>
short side = $short_side<br>
Top long side = $top_long<br>";
*/

// Create the highlights image
$width_short = $width-1;
$width_long = $width+1;
$width_top = $width-2;
$cmd = " -size ".$width."x".$height." xc:none -stroke rgba(211,211,211,0.6) -strokewidth 3 -fill none -draw \" line 0,-2 $width_short,1 \" -draw \" line $width_top,2 $width_long,$height  \"";
exec("convert $cmd highlights.miff");

// Crop for the edges
$cmd = " temp.png -clone 0 -crop ".$width."x".$height."+".$edge."+".$edge." highlights.miff -composite -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 appended.png");

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

// Alternative style
$cmd = " appended.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 test_canvas.png");

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

// Cleanup
foreach ( glob("*.miff") as $filename ) { unlink($filename); }
resim.jpg =>Image

help me please
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Canvas wrap transformation

Post by Bonzo »

What version of Imagemagick are you using?

Have you tried the code with a different image as this one may be to small?
yazilim
Posts: 6
Joined: 2013-02-07T23:42:45-07:00
Authentication code: 6789

Re: Canvas wrap transformation

Post by yazilim »

Bonzo wrote:What version of Imagemagick are you using?

Have you tried the code with a different image as this one may be to small?
thank bonzo

ime using version =>
ImageMagick-6.7.6

i'm testing to different image , but did not :(
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Canvas wrap transformation

Post by Bonzo »

Are you on a Windows machine?

I would suggest commenting this line out and see which images were generated OK.

Code: Select all

// Cleanup
// foreach ( glob("*.miff") as $filename ) { unlink($filename); }
yazilim
Posts: 6
Joined: 2013-02-07T23:42:45-07:00
Authentication code: 6789

Re: Canvas wrap transformation

Post by yazilim »

Bonzo wrote:Are you on a Windows machine?

I would suggest commenting this line out and see which images were generated OK.

Code: Select all

// Cleanup
// foreach ( glob("*.miff") as $filename ) { unlink($filename); }
i doing to but did not

machine=> Linux
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Canvas wrap transformation

Post by Bonzo »

You could try changing all the exec( ) lines to this style and see if you get any errors.

Code: Select all

$array=array(); 
echo "<pre>";
exec("convert $cmd highlights.miff 2>&1", $array);  
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";
yazilim
Posts: 6
Joined: 2013-02-07T23:42:45-07:00
Authentication code: 6789

Re: Canvas wrap transformation

Post by yazilim »

Bonzo wrote:You could try changing all the exec( ) lines to this style and see if you get any errors.

Code: Select all

$array=array(); 
echo "<pre>";
exec("convert $cmd highlights.miff 2>&1", $array);  
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";
errors=>

Code: Select all

Array
(
)

1

Array
(
    [0] => convert: unable to open image `right.miff': No such file or directory @ error/blob.c/OpenBlob/2617.
    [1] => convert: no images defined `right_edge.miff' @ error/convert.c/ConvertImageCommand/3021.
)

1

Array
(
    [0] => convert: unable to open image `top.miff': No such file or directory @ error/blob.c/OpenBlob/2617.
    [1] => convert: no images defined `top_edge.miff' @ error/convert.c/ConvertImageCommand/3021.
)
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Canvas wrap transformation

Post by Bonzo »

I pressume you can get simple Imagemagick commands to work like a straight forward resize?

Have you changed the permissions on the folder you are saving to - 777 or 755

It looks like the code is failing here:

Code: Select all

// Crop for the edges
$cmd = " temp.png -clone 0 -crop ".$width."x".$height."+".$edge."+".$edge." highlights.miff -composite -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 ");
The standard output from ImageMagick is 0 for sucsesful image generation and 1 for a failure.
Post Reply