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

Implemented interlace support for GD, Imagick, and Gmagick. #196

Merged
merged 4 commits into from
Feb 5, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions lib/Imagine/Gd/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,27 @@ public function layers()

return $this->layers;
}

/**
* {@inheritdoc}
**/
public function interlace($type)
{
$supportedInterlaceTypes = array(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'm happy to do that to help maintain consistency. :)

Thanks.

ImageInterface::INTERLACE_NONE => 0,
ImageInterface::INTERLACE_LINE => 1,
ImageInterface::INTERLACE_PLANE => 1,
ImageInterface::INTERLACE_PARTITION => 1,
);

if (!array_key_exists($supportedInterlaceTypes)) {
throw new InvalidArgumentException('Unsupported interlace type');
}

imageinterlace($this->resource, $supportedInterlaceTypes[$type]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still love to find out what interlacing scheme GD implements so this intended behaviour could be better handled and documented.


return $this;
}

/**
* Internal
Expand Down
21 changes: 21 additions & 0 deletions lib/Imagine/Gmagick/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,27 @@ public function layers()
{
return $this->layers;
}

/**
* {@inheritdoc}
**/
public function interlace($type)
{
$supportedInterlaceTypes = array(
ImageInterface::INTERLACE_NONE => \Gmagick::INTERLACE_NO,
ImageInterface::INTERLACE_LINE => \Gmagick::INTERLACE_LINE,
ImageInterface::INTERLACE_PLANE => \Gmagick::INTERLACE_PLANE,
ImageInterface::INTERLACE_PARTITION => \Gmagick::INTERLACE_PARITION,
);

if (!array_key_exists($supportedInterlaceTypes)) {
throw new InvalidArgumentException('Unsupported interlace type');
}

$this->gmagick->setInterlaceScheme($supportedInterlaceTypes[$type]);

return $this;
}

/**
* Internal
Expand Down
14 changes: 14 additions & 0 deletions lib/Imagine/Image/ImageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ interface ImageInterface extends ManipulatorInterface
{
const RESOLUTION_PIXELSPERINCH = 'ppi';
const RESOLUTION_PIXELSPERCENTIMETER = 'ppc';

const INTERLACE_NONE = 'none';
const INTERLACE_LINE = 'line';
const INTERLACE_PLANE = 'plane';
const INTERLACE_PARTITION = 'partition';

/**
* Returns the image content as a binary string
Expand Down Expand Up @@ -102,4 +107,13 @@ public function getColorAt(PointInterface $point);
* @return LayersInterface
*/
public function layers();

/**
* Enables or disables interlacing
*
* @throws InvalidArgumentException When an unsupported Interface type is supplied
*
* @return ImageInterface
*/
public function interlace($type);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did notice that the Imagick and Gmagick objects call the interlace types scheme, I wonder if it's worth changing $type to scheme too.

ImageInterface::interlace($scheme);

}
21 changes: 21 additions & 0 deletions lib/Imagine/Imagick/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,27 @@ public function get($format, array $options = array())

return $this->imagick->getImagesBlob();
}

/**
* {@inheritdoc}
**/
public function interlace($type)
{
$supportedInterlaceTypes = array(
ImageInterface::INTERLACE_NONE => \Imagick::INTERLACE_NO,
ImageInterface::INTERLACE_LINE => \Imagick::INTERLACE_LINE,
ImageInterface::INTERLACE_PLANE => \Imagick::INTERLACE_PLANE,
ImageInterface::INTERLACE_PARTITION => \Imagick::INTERLACE_PARITION,
);

if (!array_key_exists($supportedInterlaceTypes)) {
throw new InvalidArgumentException('Unsupported interlace type');
}

$this->imagick->setInterlaceScheme($supportedInterlaceTypes[$type]);

return $this;
}

/**
* @param array $options
Expand Down