/** * Apply the opacity transformation to the sfImage object * * @param sfImage * * @return sfImage */ public function transform(sfImage $image) { // Get the actual image resource $resource = $image->getAdapter()->getHolder(); //get the resource dimentions $width = $image->getWidth(); $height = $image->getHeight(); $reflection = $image->copy(); $reflection->flip()->resize($width, $this->reflection_height); $r_resource = $reflection->getAdapter()->getHolder(); $dest_resource = $reflection->getAdapter()->getTransparentImage($width, $height + $this->reflection_height); imagecopymerge($dest_resource, $resource, 0, 0, 0, 0, $width, $height, 100); imagecopymerge($dest_resource, $r_resource, 0, $height, 0, 0, $width, $this->reflection_height, 100); // Increments we are going to increase the transparency $increment = 100 / $this->reflection_height; // Overlay line we use to apply the transparency $line = imagecreatetruecolor($width, 1); // Use white as our overlay color imagefilledrectangle($line, 0, 0, $width, 1, imagecolorallocate($line, 255, 255, 255)); $tr = $this->start_transparency; // Start at the bottom of the original image for ($i = $height; $i <= $height + $this->reflection_height; $i++) { if ($tr > 100) { $tr = 100; } imagecopymerge($dest_resource, $line, 0, $i, 0, 0, $width, 1, $tr); $tr += $increment; } // To set a new resource for the image object $image->getAdapter()->setHolder($dest_resource); return $image; }
public function copyImage(Image $image) { $newImage = $image->copy(); $newImage->setFilename($this->defaults['default_image']['filename']); return $newImage; }