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

Bindings for compression quality and stripping #23

Merged
merged 3 commits into from May 27, 2012

Conversation

2 participants
@dvukolov
Contributor

dvukolov commented May 26, 2012

In the course of a local web project I added a couple of bindings for manipulating the resulting image file size: getting and setting image compression quality, as well as stripping the image of comments and profile data to reduce the file size. In my case this was extremely useful for processing jpeg images before uploading them to a web server.

@dahlia

This comment has been minimized.

Collaborator

dahlia commented May 27, 2012

Thanks for your code. It is almost fine, but some trivial things outstand. I will comment to these things.

result = library.MagickStripImage(self.wand)
if not result:
self.raise_exception()

This comment has been minimized.

@dahlia

dahlia May 27, 2012

Collaborator

How can we test Image.strip() method?

This comment has been minimized.

@dvukolov

dvukolov May 27, 2012

Contributor

Without actually looking into the presence of profiles and comments in an image, it's possible to simply check the file size before and after stripping. The beach.jpg from assets is a good example, containing Exif data and color profile. Like this:

@tests.test
def strip():
    """Strips the image of all profiles and comments."""
    with Image(filename=asset('beach.jpg')) as img:
        strio = StringIO.StringIO()
        img.save(file=strio)
        len_unstripped = strio.tell()
        strio.truncate(0)
        img.strip()
        img.save(file=strio)
        len_stripped = strio.tell()
        assert len_unstripped > len_stripped
"""Set compression quality for the image.
:param quality: new compression quality setting
:type quality: :class:`numbers.Integral`

This comment has been minimized.

@dahlia

dahlia May 27, 2012

Collaborator

Above two lines are incorrectly aligned. It would be instead:

        """Set compression quality for the image.

        :param quality: new compression quality setting
        :type quality: :class:`numbers.Integral`

        """

This comment has been minimized.

@dvukolov

dvukolov May 27, 2012

Contributor

Corrected that locally, thanks! If you're fine with both changes, I'll make a new commit.

@dahlia

This comment has been minimized.

Collaborator

dahlia commented May 27, 2012

@dvukolov I will merge it into master when you make a new commit. 👍

dahlia added a commit that referenced this pull request May 27, 2012

Merge pull request #23 from dvukolov/master
Bindings for compression quality and stripping

@dahlia dahlia merged commit 8b1d86d into emcconville:master May 27, 2012

@dahlia

This comment has been minimized.

Collaborator

dahlia commented May 27, 2012

Thanks for your effort. I merged it. ☀️

dahlia added a commit that referenced this pull request May 27, 2012

@dahlia

This comment has been minimized.

Collaborator

dahlia commented May 27, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment