Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>But - <b>It is possible with GD and fast!!</b> in comparison with ImageMagick<br><img src="https://i.stack.imgur.com/oqY2S.png" alt="enter image description here"> Create a new image with the size of <i>(2*SourceWidth)/PI</i>.<br> Walk trough each pixel of the new image and find the distance from the center. <i>d<sub>source</sub>=hypot(x-centerX,y-centerY)</i><br> Find the corresponding distance in the source image by <i>d<sub>dest.</sub>=2*r*asin(d<sub>source</sub>/r)/2</i><br> <i>r</i> is the half width of the destination image.<br> See examples with bench mark: <a href="http://meindesign.net/picture2bubble/picture2bubble.php" rel="nofollow noreferrer">http://meindesign.net/picture2bubble/picture2bubble.php</a></p> <pre><code>function fisheye($infilename,$outfilename){ $im=imagecreatefrompng($infilename); $ux=imagesx($im);//Source imgage width(x) $uy=imagesy($im);//Source imgage height(y) $umx=$ux/2;//Source middle $umy=$uy/2; if($ux&gt;$uy)$ow=2*$uy/pi();//Width for the destionation image else $ow=2*$ux/pi(); $out=imagecreatetruecolor($ow+1,$ow+1); $trans=imagecolortransparent($out,ImageColorAllocate($out,0,0,0)); imagefill($im,1,1,$trans); for($c=0;$c&lt;imagecolorstotal($im);$c++){//Copy palette $col=imagecolorsforindex($im,$c); imagecolorset($out,$c,$col[red],$col[green],$col[blue]); } $om=$ow/2;//destination middle for($x=0;$x&lt;=$ow;++$x){//Loop X in destination image for($y=0;$y&lt;=$ow;++$y){//Loop y in destination image $otx=$x-$om;//X in relation to the middle $oty=$y-$om;//Y in relation to the middle $oh=hypot($otx,$oty);//distance $arc=(2*$om*asin($oh/$om))/(2); $factor=$arc/$oh; if($oh&lt;=$om){//if pixle inside radius $color=imagecolorat($im,round($otx*$factor+$umx),round($oty*$factor+$umy)); $r = ($color &gt;&gt; 16) &amp; 0xFF; $g = ($color &gt;&gt; 8) &amp; 0xFF; $b = $color &amp; 0xFF; $temp=imagecolorexact($out, $r, $g, $b); imagesetpixel($out,$x,$y,$temp); } } } imagepng($out,$outfilename); } </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    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