Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>PHP with GD can't do such a thing in an acceptable way, processing an image pixel-by-pixel will be really slow...</p> <p>Imagick does support a function that enable you to write your own expression (<a href="http://www.php.net/manual/en/function.imagick-fximage.php" rel="nofollow">fximage</a>), after that everything will be handled internally within Imagick.</p> <p>So I've find a way to do what you've requested in Imagick, I've taked the expression from <a href="http://scottpenberthy.com/2008/09/05/fisheye-effect-in-imagemagick/" rel="nofollow">"Scott builds Software" blog - fisheye effect in imagick</a>. You can read the full explanation of the expression in his blog. Further documentation of this function is available at the official <a href="http://www.imagemagick.org/script/fx.php" rel="nofollow">ImageMagick</a> site, you can learn there how you can build your own expressions.</p> <p>Please note that the PHP documentation about the return value is incorrect, I've also commented there. The function return the actual Imagick object.</p> <p>So here is your code:</p> <pre><code>&lt;?php /* Create new object */ $im = new Imagick(); /* Create new checkerboard pattern */ $im-&gt;newPseudoImage(100, 100, "pattern:checkerboard"); /* Set the image format to png */ $im-&gt;setImageFormat('png'); /* Fill background area with transparent */ $trans = Imagick::VIRTUALPIXELMETHOD_TRANSPARENT; $im-&gt;setImageVirtualPixelMethod($trans); /* Activate matte */ $im-&gt;setImageMatte(true); /* This is the expression that define how to do the fisheye effect */ $distort_expression = 'kk=w*0.5; ll=h*0.5; dx=(i-kk); dy=(j-ll); aa=atan2(dy,dx); rr=hypot(dy,dx); rs=rr*rr/hypot(kk,ll); px=kk+rs*cos(aa); py=ll+rs*sin(aa); p{px,py}'; /* Perform the distortion */ $im = $im-&gt;fxImage($distort_expression); /* Ouput the image */ header("Content-Type: image/png"); echo $im; ?&gt; </code></pre> <p>Anyway, keep in mind that this is still slow, be careful with whatever you do with that...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload