/** * Apply the transform to the sfImage object. * * @param integer * @return sfImage */ protected function transform(sfImage $image) { // Check we have a valid image resource $resource = $image->getAdapter()->getHolder(); $resource->flopImage(); return $image; }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $resourcex = imagesx($resource); $resourcey = imagesy($resource); for ($x = 0; $x < $resourcex; ++$x) { for ($y = 0; $y < $resourcey; ++$y) { $distx = rand(-$this->scatter_factor, $this->scatter_factor); $disty = rand(-$this->scatter_factor, $this->scatter_factor); // keep inside the image boundaries if ($x + $distx >= $resourcex) { continue; } if ($x + $distx < 0) { continue; } if ($y + $disty >= $resourcey) { continue; } if ($y + $disty < 0) { continue; } $oldcol = imagecolorat($resource, $x, $y); $newcol = imagecolorat($resource, $x + $distx, $y + $disty); imagesetpixel($resource, $x, $y, $newcol); imagesetpixel($resource, $x + $distx, $y + $disty, $oldcol); } } return $image; }
protected function createMask(sfImage $image, $w, $h) { // Create a mask png image of the area you want in the circle/ellipse (a 'magicpink' image with a black shape on it, with black set to the colour of alpha transparency) - $mask $mask = $image->getAdapter()->getTransparentImage($w, $h); // Set the masking colours if (false === $this->getColor() || 'image/png' == $image->getMIMEType()) { $mask_black = imagecolorallocate($mask, 0, 0, 0); } else { $mask_black = $image->getAdapter()->getColorByHex($mask, $this->getColor()); } // Cannot use white as transparent mask if color is set to white if ($this->getColor() === '#FFFFFF' || $this->getColor() === false) { $mask_transparent = imagecolorallocate($mask, 255, 0, 0); } else { $mask_color = imagecolorsforindex($mask, imagecolorat($image->getAdapter()->getHolder(), 0, 0)); $mask_transparent = imagecolorallocate($mask, $mask_color['red'], $mask_color['green'], $mask_color['blue']); } imagecolortransparent($mask, $mask_transparent); imagefill($mask, 0, 0, $mask_black); // Draw the rounded rectangle for the mask $this->imagefillroundedrect($mask, 0, 0, $w, $h, $this->getRadius(), $mask_transparent); $mask_image = clone $image; $mask_image->getAdapter()->setHolder($mask); return $mask_image; }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ public function execute(sfImage $image) { // Check we have a valid image holder if (false === $image->getAdapter()->hasHolder()) { throw new sfImageTransformException(sprintf('Cannot perform transform: %s invalid image resource', get_class($this))); } return $this->transform($image); }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $x = imagesx($resource); $y = imagesy($resource); $image->resize(round($x * $this->scale), round($y * $this->scale)); return $image; }
public function transform(sfImage $image) { if ($this->resize) { $this->src->resize($this->width, $this->height); } imagecopy($image->getAdapter()->getHolder(), $this->src->getAdapter()->getHolder(), $this->x, $this->y, 0, 0, $this->width, $this->height); return $image; }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $x = $resource->getImageWidth(); $y = $resource->getImageHeight(); $image->resize(round($x * $this->scale), round($y * $this->scale)); return $image; }
/** * Apply the transformation to the image and returns the image thumbnail */ protected function transform(sfImage $image) { // Work out where we need to draw to $offset = $this->getThickness() / 2; $mod = $this->getThickness() % 2; $x2 = $image->getWidth() - $offset - ($mod === 0 ? 1 : 0); $y2 = $image->getHeight() - $offset - ($mod === 0 ? 1 : 0); $image->rectangle($offset, $offset, $x2, $y2, $this->getThickness(), $this->getColor()); return $image; }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); if (function_exists('imagefilter')) { imagefilter($resource, IMG_FILTER_NEGATE); } else { throw new sfImageTransformException(sprintf('Cannot perform transform, GD does not support imagefilter ')); } return $image; }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); // Set the defined color as transparent if ($this->color !== '') { $color = $image->getAdapter()->getColorByHex($resource, $this->color); } else { $color = imagecolorat($resource, 0, 0); } imagecolortransparent($resource, $color); return $image; }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $resourcex = imagesx($resource); $resourcey = imagesy($resource); for ($x = 0; $x < $resourcex; $x += $this->block_size) { for ($y = 0; $y < $resourcey; $y += $this->block_size) { $rgb = imagecolorat($resource, $x, $y); imagefilledrectangle($resource, $x, $y, $x + $this->block_size - 1, $y + $this->block_size - 1, $rgb); } } return $image; }
/** * Apply the transform to the sfImage object. * * @param integer * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $x = imagesx($resource); $y = imagesy($resource); $dest_resource = $image->getAdapter()->getTransparentImage($x, $y); for ($h = 0; $h < $y; $h++) { imagecopy($dest_resource, $resource, 0, $h, 0, $y - $h - 1, $x, 1); } // Tidy up imagedestroy($resource); // Replace old image with flipped version $image->getAdapter()->setHolder($dest_resource); return $image; }
/** * Apply the transform to the sfImage object. * * @access protected * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $resourcex = imagesx($resource); $resourcey = imagesy($resource); for ($x = 0; $x < $resourcex; ++$x) { for ($y = 0; $y < $resourcey; ++$y) { $newr = 0; $newg = 0; $newb = 0; $colours = array(); $thiscol = imagecolorat($resource, $x, $y); for ($k = $x - $this->blur_pixels; $k <= $x + $this->blur_pixels; ++$k) { for ($l = $y - $this->blur_pixels; $l <= $y + $this->blur_pixels; ++$l) { if ($k < 0) { $colours[] = $thiscol; continue; } if ($k >= $resourcex) { $colours[] = $thiscol; continue; } if ($l < 0) { $colours[] = $thiscol; continue; } if ($l >= $resourcey) { $colours[] = $thiscol; continue; } $colours[] = imagecolorat($resource, $k, $l); } } foreach ($colours as $colour) { $newr += $colour >> 16 & 0xff; $newg += $colour >> 8 & 0xff; $newb += $colour & 0xff; } $numelements = count($colours); $newr /= $numelements; $newg /= $numelements; $newb /= $numelements; $newcol = imagecolorallocate($resource, $newr, $newg, $newb); imagesetpixel($resource, $x, $y, $newcol); } } return $image; }
/** * Apply the transform to the sfImage object. * * @param integer * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $x = imagesx($resource); $y = imagesy($resource); imagealphablending($resource, true); $dest_resource = $image->getAdapter()->getTransparentImage($x, $y); imagealphablending($dest_resource, true); for ($w = 0; $w < $x; $w++) { imagecopy($dest_resource, $resource, $w, 0, $x - $w - 1, 0, 1, $y); } // Tidy up imagedestroy($resource); // Replace old image with flipped version $image->getAdapter()->setHolder($dest_resource); return $image; }
/** * Apply the opacity transformation to the sfImage object * * @param sfImage * * @return sfImage */ protected function transform(sfImage $image) { $new_img = $image->getAdapter()->getTransparentImage($image->getWidth(), $image->getHeight()); imagealphablending($new_img, false); imagesavealpha($new_img, true); $opacity = (int) round(127 - 127 / 100 * $this->getOpacity()); // imagesavealpha($new_img, true); $width = $image->getWidth(); $height = $image->getHeight(); for ($x = 0; $x < $width; $x++) { for ($y = 0; $y < $height; $y++) { $rgb = imagecolorat($image->getAdapter()->getHolder(), $x, $y); $r = $rgb >> 16 & 0xff; $g = $rgb >> 8 & 0xff; $b = $rgb & 0xff; $alpha = ($rgb & 0x7f000000) >> 24; $new_opacity = $alpha + (127 - $alpha) / 100 * $this->getOpacity(); $colors[$alpha] = $new_opacity; $color = imagecolorallocatealpha($new_img, $r, $g, $b, $new_opacity); imagesetpixel($new_img, $x, $y, $color); } } $image->getAdapter()->setHolder($new_img); return $image; }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $resourcex = imagesx($resource); $resourcey = imagesy($resource); for ($x = 0; $x < $resourcex; ++$x) { for ($y = 0; $y < $resourcey; ++$y) { $rgb = imagecolorat($resource, $x, $y); $red = $rgb >> 16 & 0xff; $green = $rgb >> 8 & 0xff; $blue = $rgb & 0xff; $red = (int) (($red + $green + $blue) / 3); $modifier = rand(-$this->density, $this->density); $red += $modifier; $green += $modifier; $blue += $modifier; // Max value is 255 // Min value is 0 if ($red > 255) { $red = 255; } if ($green > 255) { $green = 255; } if ($blue > 255) { $blue = 255; } if ($red < 0) { $red = 0; } if ($green < 0) { $green = 0; } if ($blue < 0) { $blue = 0; } $newcol = imagecolorallocate($resource, $red, $green, $blue); imagesetpixel($resource, $x, $y, $newcol); } } return $image; }
/** * Apply the transform to the sfImage object. * * @access protected * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $color = sprintf('rgb(%d,%d,%d)', $this->getRed(), $this->getGreen(), $this->getBlue()); $pixel = new ImagickPixel($color); $resource->colorizeImage($pixel, $pixel); return $image; }
/** * Computes the offset of the overlayed image * and sets the top and left coordinates based on the named position * * @param sfImage $image canvas image * * @return void */ protected function computeCoordinates(sfImage $image) { $position = $this->getPosition(); // no named position nothing to compute if (is_null($position)) { return; } $resource = $image->getAdapter()->getHolder(); $resource_x = $resource->getImageWidth(); $resource_y = $resource->getImageHeight(); $overlay = $this->getOverlay()->getAdapter()->getHolder(); $overlay_x = $overlay->getImageWidth(); $overlay_y = $overlay->getImageHeight(); switch ($position) { case 'top': case 'top-left': $this->setLeft(0); $this->setTop(0); break; case 'bottom': case 'bottom-left': $this->setLeft(0); $this->setTop($resource_y - $overlay_y); break; case 'left': $this->setLeft(0); $this->setTop(round(($resource_y - $overlay_y) / 2)); break; case 'right': $this->setLeft(round($resource_x - $overlay_x)); $this->setTop(round(($resource_y - $overlay_y) / 2)); break; case 'top-right': $this->setLeft($resource_x - $overlay_x); $this->setTop(0); break; case 'bottom-right': $this->setLeft($resource_x - $overlay_x); $this->setTop($resource_y - $overlay_y); break; case 'bottom-center': $this->setLeft(round(($resource_x - $overlay_x) / 2)); $this->setTop(round($resource_y - $overlay_y)); break; case 'center': case 'middle-center': $this->setLeft(round(($resource_x - $overlay_x) / 2)); $this->setTop(round(($resource_y - $overlay_y) / 2)); break; case 'middle-left': $this->setLeft(0); $this->setTop(round(($resource_y - $overlay_y) / 2)); break; case 'middle-right': $this->setLeft(round($resource_x - $overlay_x)); $this->setTop(round(($resource_y - $overlay_y) / 2)); break; case 'bottom-left': default: $this->setLeft(0); $this->setTop($resource_y - $overlay_y); break; } }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); imagesetthickness($resource, $this->thickness); if (!is_null($this->fill)) { if (!is_object($this->fill)) { imagefilledellipse($resource, $this->x, $this->y, $this->width, $this->height, $image->getAdapter()->getColorByHex($resource, $this->fill)); } if (is_object($this->fill)) { imagefilledellipse($resource, $this->x, $this->y, $this->width, $this->height, $image->getAdapter()->getColorByHex($resource, $this->color)); $image->fill($this->x, $this->y, $this->fill); } if ($this->color !== "" && $this->fill !== $this->color) { imageellipse($resource, $this->x, $this->y, $this->width, $this->height, $image->getAdapter()->getColorByHex($resource, $this->color)); } } else { imageellipse($resource, $this->x, $this->y, $this->width, $this->height, $image->getAdapter()->getColorByHex($resource, $this->color)); } return $image; }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $draw = new ImagickDraw(); $draw->setStrokeWidth($this->thickness); if (!is_null($this->color)) { $stroke = new ImagickPixel(); $stroke->setColor($this->color); $draw->setStrokeColor($stroke); } if (!is_null($this->fill)) { $fill = new ImagickPixel(); $fill->setColor($this->fill); $draw->setFillColor($fill); } $draw->rectangle($this->x1, $this->y1, $this->x2, $this->y2); $resource->drawImage($draw); return $image; }
/** * Apply the transformation to the image and returns the image thumbnail */ protected function transform(sfImage $image) { $resource_w = $image->getWidth(); $resource_h = $image->getHeight(); $scale_w = $this->getWidth() / $resource_w; $scale_h = $this->getHeight() / $resource_h; $method = $this->getMethod(); switch ($method) { case 'deflate': case 'inflate': return $image->resize($this->getWidth(), $this->getHeight()); case 'left': case 'right': case 'top': case 'bottom': case 'top-left': case 'top-right': case 'bottom-left': case 'bottom-right': case 'center': $image->scale(max($scale_w, $scale_h)); if (false !== strstr($method, 'top')) { $top = 0; } else { if (false !== strstr($method, 'bottom')) { $top = $image->getHeight() - $this->getHeight(); } else { $top = (int) round(($image->getHeight() - $this->getHeight()) / 2); } } if (false !== strstr($method, 'left')) { $left = 0; } else { if (false !== strstr($method, 'right')) { $left = $image->getWidth() - $this->getWidth(); } else { $left = (int) round(($image->getWidth() - $this->getWidth()) / 2); } } return $image->crop($left, $top, $this->getWidth(), $this->getHeight()); case 'scale': return $image->scale(min($scale_w, $scale_h)); case 'fit': default: $img = clone $image; $image->create($this->getWidth(), $this->getHeight()); // Set a background color if specified if (!is_null($this->getBackground()) && $this->getBackground() != '') { $image->fill(0, 0, $this->getBackground()); } $img->scale(min($this->getWidth() / $img->getWidth(), $this->getHeight() / $img->getHeight())); $image->overlay($img, 'center'); return $image; } }
/** * Computes the offset of the overlayed image and sets * the top and left coordinates based on the named position * * @param sfImage $image canvas image * * @return boolean */ public function computeCoordinates(sfImage $image) { $position = $this->getPosition(); if (is_null($position)) { return false; } $resource = $image->getAdapter()->getHolder(); $resource_x = ImageSX($resource); $resource_y = ImageSY($resource); $overlay = $this->getOverlay()->getAdapter()->getHolder(); $overlay_x = ImageSX($overlay); $overlay_y = ImageSY($overlay); switch (strtolower($position)) { case 'top': case 'top-left': $this->setLeft(0); $this->setTop(0); break; case 'bottom': case 'bottom-left': $this->setLeft(0); $this->setTop($resource_y - $overlay_y); break; case 'left': $this->setLeft(0); $this->setTop(round(($resource_y - $overlay_y) / 2)); break; case 'right': $this->setLeft(round($resource_x - $overlay_x)); $this->setTop(round(($resource_y - $overlay_y) / 2)); break; case 'top-right': $this->setLeft($resource_x - $overlay_x); $this->setTop(0); break; case 'bottom-right': $this->setLeft($resource_x - $overlay_x); $this->setTop($resource_y - $overlay_y); break; case 'bottom-center': $this->setLeft(round(($resource_x - $overlay_x) / 2)); $this->setTop(round($resource_y - $overlay_y)); break; case 'center': case 'middle-center': $this->setLeft(round(($resource_x - $overlay_x) / 2)); $this->setTop(round(($resource_y - $overlay_y) / 2)); break; case 'middle-left': $this->setLeft(0); $this->setTop(round(($resource_y - $overlay_y) / 2)); break; case 'middle-right': $this->setLeft(round($resource_x - $overlay_x)); $this->setTop(round(($resource_y - $overlay_y) / 2)); break; case 'bottom-left': default: $this->setLeft(0); $this->setTop($resource_y - $overlay_y); break; } return true; }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); if (!is_null($this->style)) { imagesetstyle($this->style); } if ($this->thickness === 1) { imageline($resource, $this->x1, $this->y1, $this->x2, $this->y2, $image->getAdapter()->getColorByHex($resource, $this->color)); } else { if ($this->x1 === $this->x2 || $this->y1 === $this->y2) { imagefilledrectangle($resource, round(min($this->x1, $this->x2) - $this->thickness), round(min($this->y1, $this->y2) - $this->thickness), round(max($this->x1, $this->x2) + $this->thickness), round(max($this->y1, $this->y2) + $this->thickness), $image->getAdapter()->getColorByHex($resource, $this->color)); } else { $k = ($this->y2 - $this->y1) / ($this->x2 - $this->x1); $a = $this->thickness / sqrt(1 + pow($k, 2)); $points = array(round($this->x1 - (1 + $k) * $a), round($this->y1 + (1 - $k) * $a), round($this->x1 - (1 - $k) * $a), round($this->y1 - (1 + $k) * $a), round($this->x2 + (1 + $k) * $a), round($this->y2 - (1 - $k) * $a), round($this->x2 + (1 - $k) * $a), round($this->y2 + (1 + $k) * $a)); $color = $image->getAdapter()->getColorByHex($resource, $this->color); imagefilledpolygon($resource, $points, 4, $color); imagepolygon($resource, $points, 4, $color); } } return $image; }
/** * Apply the transform to the sfImage object. * * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); imagegammacorrect($resource, $this->input_gamma, $this->output_gamma); return $image; }
/** * Apply the transform to the sfImage object. * * @access protected * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $dest_resource = $image->getAdapter()->getTransparentImage($this->width, $this->height); // Preserving transparency for alpha PNGs imagealphablending($dest_resource, false); imagesavealpha($dest_resource, true); imagecopy($dest_resource, $resource, 0, 0, $this->left, $this->top, $this->width, $this->height); // Tidy up imagedestroy($resource); // Replace old image with flipped version $image->getAdapter()->setHolder($dest_resource); return $image; }
/** * Apply the transform to the sfImage object. * * @access protected * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); // Use GD's built in filter if (function_exists('imagefilter')) { // we have to check for the php version as alpha support was added to imagefilter/IMG_FILTER_COLORIZE in 5.2.5 if (strnatcmp(phpversion(), '5.2.5') >= 0) { imagefilter($resource, IMG_FILTER_COLORIZE, $this->red_tint, $this->green_tint, $this->blue_tint, $this->alpha); } else { imagefilter($resource, IMG_FILTER_COLORIZE, $this->red_tint, $this->green_tint, $this->blue_tint); } } else { $resourcex = imagesx($resource); $resourcey = imagesy($resource); for ($x = 0; $x < $resourcex; ++$x) { for ($y = 0; $y < $resourcey; ++$y) { $rgb = imagecolorat($resource, $x, $y); $red = $rgb >> 16 & 0xff; $green = $rgb >> 8 & 0xff; $blue = $rgb & 0xff; $red = (int) (($red + $green + $blue) / 3); $green = $red + $this->green_tint; $blue = $red + $this->blue_tint; $red += $this->red_tint; // Max value is 255 // Min value is 0 if ($red > 255) { $red = 255; } if ($green > 255) { $green = 255; } if ($blue > 255) { $blue = 255; } if ($red < 0) { $red = 0; } if ($green < 0) { $green = 0; } if ($blue < 0) { $blue = 0; } $newcol = imagecolorallocate($resource, $red, $green, $blue); imagesetpixel($resource, $x, $y, $newcol); } } } return $image; }
protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $resource->normalizeImage(); $resource->unsharpMaskImage($this->getRadius(), $this->getSigma(), $this->getAmount(), $this->getThreshold()); return $image; }
protected function transformDefault(sfImage $image) { $w = $image->getWidth(); $h = $image->getHeight(); $resource = $image->getAdapter()->getHolder(); $mask = $this->getMask()->getAdapter()->getHolder(); imagealphablending($resource, true); $resource_transparent = imagecolorallocate($resource, 0, 0, 0); imagecolortransparent($resource, $resource_transparent); // Copy $mask over the top of $resource maintaining the Alpha transparency imagecopymerge($resource, $mask, 0, 0, 0, 0, $w, $h, 100); }
/** * Apply the transform to the sfImage object. * * @access protected * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $resource->cropImage($this->getWidth(), $this->getHeight(), $this->getLeft(), $this->getTop()); $resource->setImagePage($this->getWidth(), $this->getHeight(), 0, 0); return $image; }
/** * Apply the transform to the sfImage object. * * @access protected * @param sfImage * @return sfImage */ protected function transform(sfImage $image) { $resource = $image->getAdapter()->getHolder(); $resource->modulateImage($this->getBrightness(), 100, 100); return $image; }