public function apply($resource) { if ($this->settings->xoffset < 0) { $xextra = 0 - $this->settings->xoffset; } else { $xextra = $this->settings->xoffset; } if ($this->settings->yoffset < 0) { $yextra = 0 - $this->settings->yoffset; } else { $yextra = $this->settings->yoffset; } $rextra = ceil($this->settings->radius / 2); $image = (object) array('width' => imagesx($resource->image) + $rextra + $xextra, 'height' => imagesy($resource->image) + $rextra + $yextra); $source = (object) array('top' => $this->settings->yoffset < 0 ? $yextra + $rextra : 0, 'left' => $this->settings->xoffset < 0 ? $xextra + $rextra : 0, 'width' => imagesx($resource->image), 'height' => imagesy($resource->image)); $shadow = (object) array('top' => $this->settings->yoffset < 0 ? $rextra : $yextra, 'left' => $this->settings->xoffset < 0 ? $rextra : $xextra, 'width' => imagesx($resource->image) - 1, 'height' => imagesy($resource->image) - 1); //var_dump($shadow); //exit; $new = imagecreatetruecolor($image->width, $image->height); $colour = new Colour($this->settings->bg); $bg = $colour->allocate($new); imagefill($new, 0, 0, $bg); $colour = new Colour($this->settings->fg); $fg = $colour->allocate($new); imagefilledrectangle($new, $shadow->left, $shadow->top, $shadow->left + $shadow->width, $shadow->top + $shadow->height, $fg); if ($this->settings->radius > 0) { $times = 0; while (++$times != $this->settings->radius) { imagefilter($new, IMG_FILTER_GAUSSIAN_BLUR); } } imagecopyresampled($new, $resource->image, $source->left, $source->top, 0, 0, $source->width, $source->height, $source->width, $source->height); $resource->image = $new; }
public function apply($resource) { $width = $this->settings->width; $height = $this->settings->height; // Find original dimensions: $imageWidth = imagesx($resource->image); $imageHeight = imagesy($resource->image); if ($width < 1) { $width = $imageWidth; } if ($height < 1) { $height = $imageHeight; } $colour = new Colour($this->settings->bg); // Prepare new image: $new = imagecreatetruecolor($width, $height); $bg = $colour->allocate($new); imagefill($new, 0, 0, $bg); // Calculate X alignment: if ($this->settings->xalign == 'left') { $offsetX = 0; } else { if ($this->settings->xalign == 'right') { $offsetX = round(min($imageWidth, $width) - max($imageWidth, $width)); } else { $xalign = 2; if (is_numeric($this->settings->yalign)) { $xalign = (int) $this->settings->yalign / 25; } $offsetX = round((min($imageWidth, $width) - max($imageWidth, $width)) / $xalign); } } // Invert X: if ($imageWidth < $width) { $offsetX = 0 - $offsetX; } // Calculate Y alignment: if ($this->settings->yalign == 'top') { $offsetY = 0; } else { if ($this->settings->yalign == 'bottom') { $offsetY = round(min($imageHeight, $height) - max($imageHeight, $height)); } else { $yalign = 2; if (is_numeric($this->settings->yalign)) { $yalign = (int) $this->settings->yalign / 25; } $offsetY = round((min($imageHeight, $height) - max($imageHeight, $height)) / $yalign); } } // Invert Y: if ($imageHeight < $height) { $offsetY = 0 - $offsetY; } imagecopyresampled($new, $resource->image, $offsetX, $offsetY, 0, 0, $imageWidth, $imageHeight, $imageWidth, $imageHeight); $resource->image = $new; }
public function apply($resource) { $width = $this->settings->width; $height = $this->settings->height; // Find original dimensions: $imageWidth = imagesx($resource->image); $imageHeight = imagesy($resource->image); if ($this->settings->max) { /* for images that are smaller than the filter */ if ($imageHeight < $this->settings->height && $imageWidth < $this->settings->width) { $height = $imageHeight; $width = $imageWidth; } /* for images that we don't want to change the canvas for in one direction */ } // Find ratios: if ($width > 0 and $height > 0) { $ratioX = $imageWidth / $width; $ratioY = $imageHeight / $height; if ($this->settings->max) { if ($ratioX > $ratioY) { $ratio = $ratioX; } else { $ratio = $ratioY; } $width = round($imageWidth / $ratio); $height = round($imageHeight / $ratio); } } else { if ($width > 0) { $ratioX = $imageWidth / $width; $height = round($imageHeight / $ratioX); $ratioY = $ratioX; } else { if ($height > 0) { $ratioY = $imageHeight / $height; $width = round($imageWidth / $ratioY); $ratioX = $ratioY; } } } $colour = new Colour($this->settings->bg); // Prepare new image: $new = imagecreatetruecolor($width, $height); $bg = $colour->allocate($new); imagefill($new, 0, 0, $bg); // Fit: if (!$this->settings->trim) { if ($ratioX > $ratioY) { $ratio = $ratioX; } else { $ratio = $ratioY; } // Trim: } else { if ($ratioX < $ratioY) { $ratio = $ratioX; } else { $ratio = $ratioY; } } // Find dimensions: $newWidth = round($imageWidth / $ratio); $newHeight = round($imageHeight / $ratio); // Calculate X alignment: if ($this->settings->xalign == 'left') { $offsetX = 0; } else { if ($this->settings->xalign == 'right') { $offsetX = round(min($newWidth, $width) - max($newWidth, $width)); } else { $xalign = 2; if (is_numeric($this->settings->yalign)) { $xalign = (int) $this->settings->yalign / 25; } $offsetX = round((min($newWidth, $width) - max($newWidth, $width)) / $xalign); } } // Invert X: if ($newWidth < $width) { $offsetX = 0 - $offsetX; } // Calculate Y alignment: if ($this->settings->yalign == 'top') { $offsetY = 0; } else { if ($this->settings->yalign == 'bottom') { $offsetY = round(min($newHeight, $height) - max($newHeight, $height)); } else { $yalign = 2; if (is_numeric($this->settings->yalign)) { $yalign = (int) $this->settings->yalign / 25; } $offsetY = round((min($newHeight, $height) - max($newHeight, $height)) / $yalign); } } // Invert Y: if ($newHeight < $height) { $offsetY = 0 - $offsetY; } imagecopyresampled($new, $resource->image, $offsetX, $offsetY, 0, 0, $newWidth, $newHeight, $imageWidth, $imageHeight); $resource->image = $new; }