Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to the function linked by @Baba I was able to alter the script to allow for semi transparent vignette effect. </p> <pre><code>&lt;?php class PhotoEffect { private $_photoLocation; private $_width; private $_height; private $_type; private $_originalImage; private $_afterImage; /** * Load image URL in constructor */ final public function __construct($photoLocation) { $this-&gt;_photoLocation = $photoLocation; if (!$size = @getimagesize($this-&gt;_photoLocation)){ throw new Exception('Image cannot be handled'); } $this-&gt;_width = $size[0]; $this-&gt;_height = $size[1]; $this-&gt;_type = $size[2]; switch ( $this-&gt;_type ) { case IMAGETYPE_GIF: $this-&gt;_originalImage = imagecreatefromgif($this-&gt;_photoLocation); break; case IMAGETYPE_JPEG: $this-&gt;_originalImage = imagecreatefromjpeg($this-&gt;_photoLocation); break; case IMAGETYPE_PNG: $this-&gt;_originalImage = imagecreatefrompng($this-&gt;_photoLocation); break; default: throw new Exception('Unknown image type'); } } /** * Destroy created images */ final private function __destruct() { if (!empty($this-&gt;_originalImage)) { imagedestroy($this-&gt;_originalImage); } if (!empty($this-&gt;_afterImage)) { imagedestroy($this-&gt;_afterImage); } } /** * Apply vignette effect */ final public function Vignette($sharp=0.4, $level=1, $alpha=1) { if (empty($this-&gt;_originalImage)) { throw new Exception('No image'); } if (!is_numeric($sharp) || !($sharp&gt;=0 &amp;&amp; $sharp&lt;=10)) { throw new Exception('sharp must be between 0 and 10'); } if (!is_numeric($level) || !($level&gt;=0 &amp;&amp; $level&lt;=1)) { throw new Exception('level must be between 0 and 10'); } if (!is_numeric($alpha) || !($alpha&gt;=0 &amp;&amp; $alpha&lt;=10)) { throw new Exception('alpha must be between 0 and 1'); } $this-&gt;_afterImage = imagecreatetruecolor($this-&gt;_width, $this-&gt;_height); imagesavealpha($this-&gt;_afterImage, true); $trans_colour = imagecolorallocatealpha($this-&gt;_afterImage, 0, 0, 0, 127); imagefill($this-&gt;_afterImage, 0, 0, $trans_colour); for($x = 0; $x &lt; $this-&gt;_width; ++$x){ for($y = 0; $y &lt; $this-&gt;_height; ++$y){ $index = imagecolorat($this-&gt;_originalImage, $x, $y); $rgb = imagecolorsforindex($this-&gt;_originalImage, $index); $l = sin(M_PI / $this-&gt;_width * $x) * sin(M_PI / $this-&gt;_height * $y); $l = pow($l, $sharp); $l = 1 - $level * (1 - $l); $rgb['red'] *= $l; $rgb['green'] *= $l; $rgb['blue'] *= $l; $rgb['alpha'] = 127 - (127 * ($l*$alpha)); $color = imagecolorallocatealpha($this-&gt;_afterImage, $rgb['red'], $rgb['green'], $rgb['blue'], $rgb['alpha']); imagesetpixel($this-&gt;_afterImage, $x, $y, $color); } } } /** * Ouput PNG with correct header */ final public function OutputPng() { if (empty($this-&gt;_afterImage)) { if (empty($this-&gt;_originalImage)) { throw new Exception('No image'); } $this-&gt;_afterImage = $this-&gt;_originalImage; } header('Content-type: image/png'); imagepng($this-&gt;_afterImage); } /** * Save PNG */ final public function SavePng($filename) { if (empty($filename)) { throw new Exception('Filename is required'); } if (empty($this-&gt;_afterImage)) { if (empty($this-&gt;_originalImage)) { throw new Exception('No image'); } $this-&gt;_afterImage = $this-&gt;_originalImage; } imagepng($this-&gt;_afterImage, $filename); } } /** * How to use */ $effect = new PhotoEffect('test.jpg'); $effect-&gt;Vignette(); $effect-&gt;OutputPng(); ?&gt; </code></pre> <p><a href="http://phpfiddle.org/main/code/4pi-kcw" rel="nofollow">Working phpfiddle</a> with the only image I could find on their server, so not that big.</p>
    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.
    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