Page 3 of 3

Re: Canvas wrap transformation

Posted: 2013-02-10T15:34:35-07:00
by yazilim
Bonzo wrote: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.
i'm editing code chmod 777 and all create file (.miff)

code =>

Code: Select all

 <?php 
// Input image
$image = "resim.jpg";

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

// 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;
chmod ("center.miff", 0777);
chmod ("right.miff", 0777);
chmod ("top_edge.miff", 0777);
chmod ("right_edge.miff", 0777);
chmod ("top.miff", 0777);


// 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 "<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); }
 ?> 

Re: Canvas wrap transformation

Posted: 2013-02-10T15:36:44-07:00
by yazilim
edit after errors ==>

Code: Select all

Array
(
    [0] => convert: geometry does not contain image `right.miff' @ warning/attribute.c/GetImageBoundingBox/241.
)

1

Array
(
    [0] => convert: geometry does not contain image `top.miff' @ warning/attribute.c/GetImageBoundingBox/241.
)

1

Re: Canvas wrap transformation

Posted: 2013-02-11T12:38:16-07:00
by Bonzo
Sorry for the confusion you only need to CHMOD the folder to 777.

Are the miff files created then?

Re: Canvas wrap transformation

Posted: 2013-02-13T00:31:12-07:00
by naeems
yazilim wrote: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
Hi yazilim,

Problem FIXED, you had problem when joining images. Make changes in the below code:

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 95x10+15+15 )  +swap -background none -layers merge +repage ";
exec(" convert $cmd appended.png");

Re: Canvas wrap transformation

Posted: 2013-05-14T08:37:08-07:00
by creekpeanut
Bonzo.

do you have a final script that you were able to use for this. If so can you post it here to share.

Thank you

Re: Canvas wrap transformation

Posted: 2013-05-14T08:59:35-07:00
by Bonzo
My original post on page 1 worked for me creekpeanut.

Re: Canvas wrap transformation

Posted: 2013-05-14T22:29:33-07:00
by anthony
Note in a recent update (just in the last few days).. The method of joining distorted images, edge-to-edge so as not to leave gaps was updated. The problem was that if you simply compose two shapes that share an edge normally, you will get a semi-transparent gap long the join. Previously the fix was to overlap the join a little though that was obviously wrong.

The real solution is that when 'merging' shapes, do the merge on a transparent background, with 'Plus' Alpha Composition, rather than the default 'Over' Alpha Composition. When you do that you do not get a semi-transparent join.

This was overlooked for a long time in the '3D Box example' in IM Examples, though in hindsight I should have recognised it for what it was.

Examples corrected
Affine Cubes
http://www.imagemagick.org/Usage/distorts/#cube3d
Perspective Boxes
http://www.imagemagick.org/Usage/distorts/#box3d

Also see (text not web formatted with examples yet)
Masks, Aligning Two Masked Images
http://www.imagemagick.org/Usage/masking/#aligning


As such in the above I recommend you use
-compose Pluse -layers merge -compose Over

This is important with any 'piece-wise' distortions of images.

Though it is just as important that the 'mask' (in this case alpha, and distort handle that properly) of the pieces also join up properly. drawn masks however tend to be 1/2 pixel wider than they should be, at this time.

Re: Canvas wrap transformation

Posted: 2014-03-19T00:12:36-07:00
by varsha.parmar
Hi lenscape,

Can you please post your code to create canvas wrap image with imageMagick.
I need php script to create canvas wrap. without actual code anyone cant understand
the logic behind this image creation. Specially once the coder is new to imageMagick.

Thanks in advance..

Re: Canvas wrap transformation

Posted: 2014-03-19T21:20:36-07:00
by anthony
varsha.parmar wrote:Hi lenscape,

Can you please post your code to create canvas wrap image with imageMagick.
I need php script to create canvas wrap. without actual code anyone cant understand
the logic behind this image creation. Specially once the coder is new to imageMagick.

Thanks in advance..
Apart from resurrecting a old topic...

The links in the post immediately before your post basically contains all the code you need to get the basic wrap effect.
After that it is just highlights and shadowing which is also covered in IM Examples.

Re: Canvas wrap transformation

Posted: 2014-03-20T21:30:44-07:00
by fmw42
varsha.parmar wrote:Hi lenscape,

Can you please post your code to create canvas wrap image with imageMagick.
I need php script to create canvas wrap. without actual code anyone cant understand
the logic behind this image creation. Specially once the coder is new to imageMagick.

Thanks in advance..

If on unix, you could try my script, 3Dcover, at the link below. If for a commercial application, then you can contact me offline regarding a license. Otherwise, it is free for non-commercial use.

Re: Canvas wrap transformation

Posted: 2014-05-01T04:13:02-07:00
by bijalbhavsar99
I have used below php code to generate canvas image.

Code: Select all

<?php

    ini_set('display_errors',1);
      $handle =  new Imagick('Wallpaper1.jpg');
       $depth = '1';

        $edge = $depth * 72;

        $width  = $handle->getImageWidth() ;// - ( $edge * 2 );
        $height = $handle->getImageHeight() ;//- ( $edge * 2 );

        $shrink    = round(( $edge * 0.7 ), 2);
        $angle     = 30; 
        $radian    = ( $angle * Pi() ) / 180;
        $alpha     = round((abs(tan($radian)) * $shrink), 2);
        $shortSide = round( ($height - $alpha ), 2);

        $topLong   = round($width + $shrink, 2);
        $handle->setImageFormat('png');

        /**
         * Central part
         */
        $centralPart = clone $handle;
        // for morror $centralPart->cropImage($width, $height, 0, 0);
        // for normal
        $centralPart->cropImage($width -$edge, $height-$edge, 0, 0);
//        $centralPart->borderImage(new ImagickPixel("transparent"), 1, 1);
        
        /**
         * Right corner
         */
        $rightCorner = clone $handle;
        $rightCorner->cropImage($edge, $height, $width - $edge, 0);
        $rightCorner->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
        $rightCorner->setBackgroundColor(new ImagickPixel('transparent')); 
        $rightCorner->setImageMatte(true);  
        
       $rightCorner->distortImage(Imagick::DISTORTION_PERSPECTIVE, array(
            
            0, 0, 0, 0,# top left 

            $edge, 0, $shrink,$alpha,# top right

            $edge, $height, $shrink, $height+$alpha,# bottom right

            0, $height, 0, $height# bottum left
        ), true); 
         
         /**
         * Top part
         */
        $topCorner = clone $handle;
        $topCorner->cropImage($handle->getImageWidth()-$edge, $edge, 0, $handle->getImageHeight()-$edge);
        $topCorner->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
        $topCorner->setImageMatte(true);
        $topCorner->setBackgroundColor(new ImagickPixel('transparent'));
        //$topCorner->rotateImage(new ImagickPixel("transparent"), 180);
        //$topCorner->flopImage();
        //$topCorner->borderImage(new ImagickPixel("transparent"), 0, 0); 
     //   $topCorner->trimImage('0');
        $topCorner->distortImage(Imagick::DISTORTION_PERSPECTIVE, array(
            0, 0, 0, 0,

            $width, 0,$width, 0,

            $width, $edge,$topLong, $alpha,

            0, $edge,$shrink, $alpha
        ), true);
         
      
        /**
         * Composite image
         */
         
        $handle = new Imagick();
        $handle->newImage(
            $rightCorner->getImageWidth() + $centralPart->getImageWidth(),
            $topCorner->getImageHeight() + $centralPart->getImageHeight(),
            new ImagickPixel('transparent')
        );
        $handle->setBackgroundColor(new ImagickPixel('transparent'));
        $handle->setImageFormat('png');
        $handle->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); 
     
        $handle->compositeimage($centralPart, Imagick::COMPOSITE_DEFAULT, 0, 0);
        $handle->compositeimage($rightCorner, Imagick::COMPOSITE_DEFAULT, $centralPart->getImageWidth(), 0);
        $handle->compositeimage($topCorner, Imagick::COMPOSITE_DEFAULT, 0, $centralPart->getImageHeight()-1);
                 /*create shadow of image */
        $shadow = $handle->clone(); 
        $shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) ); 
        $shadow->shadowImage( 80, 3, 5, 5 ); 
        $shadow->compositeImage( $handle, Imagick::COMPOSITE_OVER, 0, 0 );
       
        /*create shadow of image */
        
        $shadow->writeImage('wrap1.png');
        
        header('Content-Type: image/png'); 
        echo $shadow;
        die();
        

?>
Main Image: http://i60.tinypic.com/34jeli0.jpg

Output Image: http://i57.tinypic.com/5tx3wk.png

When we composite image 1px transparent border showing, but it is not like bridal image showing in above post.
Image

Re: Canvas wrap transformation

Posted: 2014-05-02T05:50:50-07:00
by bijalbhavsar99
fmw42 wrote:
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.

Hi fmw42,

I want to do same thing to my canvas image. But when i try to use stroke with my php code, it is not working. I am using ImageMagick 6.6.9-7 2014-03-06 Q16 version.

Can you please give me some alternative way to achieve this.

Re: Canvas wrap transformation

Posted: 2014-05-02T10:04:24-07:00
by fmw42
Post your current result to dropbox.com (public folder) or some other free image hosting service and put a link here so I can see the result. Also post your code for drawing the line in PHP. Perhaps one of the PHP experts can point out some issue.

Re: Canvas wrap transformation

Posted: 2014-05-04T21:55:10-07:00
by bijalbhavsar99
bijalbhavsar99 wrote:I have used below php code to generate canvas image.

Code: Select all

<?php

    ini_set('display_errors',1);
      $handle =  new Imagick('Wallpaper1.jpg');
       $depth = '1';

        $edge = $depth * 72;

        $width  = $handle->getImageWidth() ;// - ( $edge * 2 );
        $height = $handle->getImageHeight() ;//- ( $edge * 2 );

        $shrink    = round(( $edge * 0.7 ), 2);
        $angle     = 30; 
        $radian    = ( $angle * Pi() ) / 180;
        $alpha     = round((abs(tan($radian)) * $shrink), 2);
        $shortSide = round( ($height - $alpha ), 2);

        $topLong   = round($width + $shrink, 2);
        $handle->setImageFormat('png');

        /**
         * Central part
         */
        $centralPart = clone $handle;
        // for morror $centralPart->cropImage($width, $height, 0, 0);
        // for normal
        $centralPart->cropImage($width -$edge, $height-$edge, 0, 0);
//        $centralPart->borderImage(new ImagickPixel("transparent"), 1, 1);
        
        /**
         * Right corner
         */
        $rightCorner = clone $handle;
        $rightCorner->cropImage($edge, $height, $width - $edge, 0);
        $rightCorner->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
        $rightCorner->setBackgroundColor(new ImagickPixel('transparent')); 
        $rightCorner->setImageMatte(true);  
        
       $rightCorner->distortImage(Imagick::DISTORTION_PERSPECTIVE, array(
            
            0, 0, 0, 0,# top left 

            $edge, 0, $shrink,$alpha,# top right

            $edge, $height, $shrink, $height+$alpha,# bottom right

            0, $height, 0, $height# bottum left
        ), true); 
         
         /**
         * Top part
         */
        $topCorner = clone $handle;
        $topCorner->cropImage($handle->getImageWidth()-$edge, $edge, 0, $handle->getImageHeight()-$edge);
        $topCorner->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
        $topCorner->setImageMatte(true);
        $topCorner->setBackgroundColor(new ImagickPixel('transparent'));
        //$topCorner->rotateImage(new ImagickPixel("transparent"), 180);
        //$topCorner->flopImage();
        //$topCorner->borderImage(new ImagickPixel("transparent"), 0, 0); 
     //   $topCorner->trimImage('0');
        $topCorner->distortImage(Imagick::DISTORTION_PERSPECTIVE, array(
            0, 0, 0, 0,

            $width, 0,$width, 0,

            $width, $edge,$topLong, $alpha,

            0, $edge,$shrink, $alpha
        ), true);
         
      
        /**
         * Composite image
         */
         
        $handle = new Imagick();
        $handle->newImage(
            $rightCorner->getImageWidth() + $centralPart->getImageWidth(),
            $topCorner->getImageHeight() + $centralPart->getImageHeight(),
            new ImagickPixel('transparent')
        );
        $handle->setBackgroundColor(new ImagickPixel('transparent'));
        $handle->setImageFormat('png');
        $handle->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT); 
     
        $handle->compositeimage($centralPart, Imagick::COMPOSITE_DEFAULT, 0, 0);
        $handle->compositeimage($rightCorner, Imagick::COMPOSITE_DEFAULT, $centralPart->getImageWidth(), 0);
        $handle->compositeimage($topCorner, Imagick::COMPOSITE_DEFAULT, 0, $centralPart->getImageHeight()-1);
                 /*create shadow of image */
        $shadow = $handle->clone(); 
        $shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) ); 
        $shadow->shadowImage( 80, 3, 5, 5 ); 
        $shadow->compositeImage( $handle, Imagick::COMPOSITE_OVER, 0, 0 );
       
        /*create shadow of image */
        
        $shadow->writeImage('wrap1.png');
        
        header('Content-Type: image/png'); 
        echo $shadow;
        die();
        

?>
Main Image: http://i60.tinypic.com/34jeli0.jpg

Output Image: http://i57.tinypic.com/5tx3wk.png

When we composite image 1px transparent border showing, but it is not like bridal image showing in above post.
Image

I have already posted code and also output and main image in above post.

Re: Canvas wrap transformation

Posted: 2014-05-04T22:47:43-07:00
by fmw42
Your output png image is being converted to jpg by the site you uploaded or when it is downloaded. That does me no good in seeing if you have transparency in the gap. If there is transparency, then you can overlay it on a white background and have the gap show as white.