PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 19, 2022

[FIXED] how to make images look like a canvas or a toile with php imagick library

 September 19, 2022     image-manipulation, imagemagick, imagick, php     No comments   

Issue

I'm using php Imagick library for some image manipulation. I can distort the perspective of images but can not make them look like a canvas or a toile

>>

It would be great if someone could explain me how can I do that.

Thanks in advance


Solution

I think I managed to do what I wanted.

Here is my approach

$im = new Imagick('Desert.jpg');
$im->setImageFormat('png');


$d = $im->getImageGeometry();
$w = $d['width'];  
$h = $d['height']; 

$im3 = new Imagick();
$im3->newImage(1, $h, 'none','png');
$im3->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);

$im1 = $im->clone();;
$im1->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
$im1->setImageMatte(true);
$im1->cropImage(($w-10), $h, 0, 0);
$controlPoints = array(
                    0,0, 15,15, 
                    ($w-10),0, ($w-10),0, 
                    0,$h, 25,($h-20), 
                    ($w-10),$h, ($w-10),$h 
                    );

$im1->distortImage(Imagick::DISTORTION_BILINEAR, $controlPoints, true);

$im2 = $im->clone();
$im2->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
$im2->setImageMatte(true);

$im2->cropImage(10, $h, ($w-10), 0);


$controlPoints2 = array(
                    0,0, 0,0, 
                    10,0,10,10, 
                    0,$h, 0,$h,
                    10,$h, 10,($h-10) 
                    );

$im2->distortImage(Imagick::DISTORTION_BILINEAR, $controlPoints2, true); 

$image = new Imagick();

$image->addImage($im1);
$image->addImage($im3);
$image->addImage($im2);
$image->resetIterator();

$combined = $image->appendImages(false);

$shadow = $combined->clone(); 

$shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) ); 

$shadow->shadowImage( 50, 3, 5, 5 ); 

$shadow->compositeImage( $combined, Imagick::COMPOSITE_OVER, 0, 0 ); 

$shadow->writeImage('Desert_Distorded.png');

and the final result is

https://i.stack.imgur.com/DFj6R.png



Answered By - Onur Kucukkece
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing