Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase the image-quality #195

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/Imagine/Effects/EffectsInterface.php
Expand Up @@ -66,4 +66,16 @@ public function colorize(Color $color);
* @throws RuntimeException
*/
public function sharpen();

/**
* Sharpens the image with an unsharpMask
*
* @param float $radius
* @param float $sigma
* @param float $amount
* @param float $threshold
*
* @return ImageInterface
*/
public function unsharpMask($radius, $sigma, $amount, $threshold);
}
11 changes: 9 additions & 2 deletions lib/Imagine/Filter/Basic/Resize.php
Expand Up @@ -25,21 +25,28 @@ class Resize implements FilterInterface
*/
private $size;

/**
* @var integer
*/
private $filter;

/**
* Constructs Resize filter with given width and height
*
* @param BoxInterface $size
* @param integer|null $filter
*/
public function __construct(BoxInterface $size)
public function __construct(BoxInterface $size, $filter = null)
{
$this->size = $size;
$this->filter = $filter;
}

/**
* {@inheritdoc}
*/
public function apply(ImageInterface $image)
{
return $image->resize($this->size);
return $image->resize($this->size, $this->filter);
}
}
4 changes: 2 additions & 2 deletions lib/Imagine/Filter/Transformation.php
Expand Up @@ -164,9 +164,9 @@ public function fill(FillInterface $fill)
/**
* {@inheritdoc}
*/
public function resize(BoxInterface $size)
public function resize(BoxInterface $size, $filter = null)
{
return $this->add(new Resize($size));
return $this->add(new Resize($size, $filter));
}

/**
Expand Down
8 changes: 8 additions & 0 deletions lib/Imagine/Gd/Effects.php
Expand Up @@ -89,4 +89,12 @@ public function sharpen()

return $this;
}

/**
* {@inheritdoc}
*/
public function unsharpMask($radius, $sigma, $amount, $threshold)
{
throw new RuntimeException('Gd does not support unsharpMask yet');
}
}
2 changes: 1 addition & 1 deletion lib/Imagine/Gd/Image.php
Expand Up @@ -138,7 +138,7 @@ final public function paste(ImageInterface $image, PointInterface $start)
/**
* {@inheritdoc}
*/
final public function resize(BoxInterface $size)
final public function resize(BoxInterface $size, $filter = null)
{
$width = $size->getWidth();
$height = $size->getHeight();
Expand Down
8 changes: 8 additions & 0 deletions lib/Imagine/Gmagick/Effects.php
Expand Up @@ -89,4 +89,12 @@ public function sharpen()
{
throw new RuntimeException('Gmagick does not support sharpen yet');
}

/**
* {@inheritdoc}
*/
public function unsharpMask($radius, $sigma, $amount, $threshold)
{
throw new RuntimeException('Gmagick does not support unsharpMask yet');
}
}
12 changes: 10 additions & 2 deletions lib/Imagine/Gmagick/Image.php
Expand Up @@ -182,13 +182,21 @@ public function paste(ImageInterface $image, PointInterface $start)
/**
* {@inheritdoc}
*/
public function resize(BoxInterface $size)
public function resize(BoxInterface $size, $filter = null)
{
if ($filter == ImageInterface::FILTER_GAUSSIAN) {
$filter = \Gmagick::FILTER_GAUSSIAN;
} elseif ($filter == ImageInterface::FILTER_LANCZOS) {
$filter = \Gmagick::FILTER_LANCZOS;
} else {
$filter = \Gmagick::FILTER_UNDEFINED;
}

try {
$this->gmagick->resizeimage(
$size->getWidth(),
$size->getHeight(),
\Gmagick::FILTER_UNDEFINED,
$filter,
1
);
} catch (\GmagickException $e) {
Expand Down
3 changes: 3 additions & 0 deletions lib/Imagine/Image/ImageInterface.php
Expand Up @@ -27,6 +27,9 @@ interface ImageInterface extends ManipulatorInterface
const RESOLUTION_PIXELSPERINCH = 'ppi';
const RESOLUTION_PIXELSPERCENTIMETER = 'ppc';

const FILTER_GAUSSIAN = "fga";
const FILTER_LANCZOS = "fla";

/**
* Returns the image content as a binary string
*
Expand Down
3 changes: 2 additions & 1 deletion lib/Imagine/Image/ManipulatorInterface.php
Expand Up @@ -54,12 +54,13 @@ public function crop(PointInterface $start, BoxInterface $size);
* Resizes current image and returns self
*
* @param BoxInterface $size
* @param string|null $filter
*
* @throws RuntimeException
*
* @return ManipulatorInterface
*/
public function resize(BoxInterface $size);
public function resize(BoxInterface $size, $filter = null);

/**
* Rotates an image at the given angle.
Expand Down
14 changes: 14 additions & 0 deletions lib/Imagine/Imagick/Effects.php
Expand Up @@ -96,4 +96,18 @@ public function sharpen()

return $this;
}

/**
* {@inheritdoc}
*/
public function unsharpMask($radius, $sigma, $amount, $threshold)
{
try {
$this->imagick->unsharpMaskImage($radius, $sigma, $amount, $threshold);
} catch (\ImagickException $e) {
throw new RuntimeException('Failed to sharpen the image with unsharpMask');
}

return $this;
}
}
12 changes: 10 additions & 2 deletions lib/Imagine/Imagick/Image.php
Expand Up @@ -196,13 +196,21 @@ public function paste(ImageInterface $image, PointInterface $start)
/**
* {@inheritdoc}
*/
public function resize(BoxInterface $size)
public function resize(BoxInterface $size, $filter = null)
{
if ($filter == ImageInterface::FILTER_GAUSSIAN) {
$filter = \Imagick::FILTER_GAUSSIAN;
} elseif ($filter == ImageInterface::FILTER_LANCZOS) {
$filter = \Imagick::FILTER_LANCZOS;
} else {
$filter = \Imagick::FILTER_UNDEFINED;
}

try {
$this->imagick->resizeImage(
$size->getWidth(),
$size->getHeight(),
\Imagick::FILTER_UNDEFINED,
$filter,
1
);
} catch (\ImagickException $e) {
Expand Down