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

Monday, September 19, 2022

[FIXED] How do I distort arc image on only top and bottom sides using imagick?

 September 19, 2022     imagick, php     No comments   

Issue

I want it to be like this:

enter image description here

But I am getting this:

enter image description here

<?php
$image = new imagick( $_SERVER['DOCUMENT_ROOT']."/test/op.jpg" );
$points = array(
    90,
);
$image->setimagebackgroundcolor("#fad888");
$image->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_BACKGROUND);
$image->distortImage(\Imagick::DISTORTION_CYLINDER2PLANE, $points, true);
header("Content-Type: image/jpeg");
echo $image;

Solution

You want to use the wave filter, not the distortion filter.

<?php
$image = new Imagick("googlelogo_color_272x92dp.png");
$image->setImageBackgroundColor("#fad888");
$image->setImageVirtualPixelMethod(\Imagick::VIRTUALPIXELMETHOD_BACKGROUND);
$image->waveImage($image->getImageHeight() / -2, $image->getImageWidth() * 2);
header("Content-Type: image/jpg");
echo $image->getImageBlob();

You'll need to trim the image to remove the extra space added at the bottom. Output:

enter image description here



Answered By - miken32
Answer Checked By - Marie Seifert (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