示例#1
0
 def difference(cls, prev_image, current_image):
     """
     params are filenames
     """
     print 'diffing', prev_image, current_image
     
     f, name = cls._get_tmp_file(EXTRACT_TYPE_DIFF)
     
     print 'Saving diff to', name
     
     """
     # PIL -- This complains that some pairs of images 'do not match' Even when
     # they are generated from the same PSD and are the same pixel size. WTF.
     # USING IMAGEMAGICK INSTEAD, BITCHES
     p = PILImage.open(prev_image)
     c = PILImage.open(current_image)
     
     diff = ImageChops.difference(c, p)
     
     diff.save(f, cls.dest_format) #TODO catch IOError and do something with it.
     f.close()
     
     del p
     del c
     del diff
     """
     
     image = Image(current_image)
     other = Image(prev_image)
     
     isize = image.size
     osize = other.size
     
     offset = (0,0)
     if isize != osize:
         #enabling this makes the diff always the same size as the largest one
         #disabling makes it the size of the most current one. Hopefully this doesnt
         #happen very often...
         if False:#isize < osize: #basically, if both x and y components are less
             #swap; image is always the larger one
             tmp = image
             image = other
             other = tmp
             
             tmp = isize
             isize = osize
             osize = tmp
         
         offset = ((isize[0] - osize[0])/2, (isize[1] - osize[1])/2)
     
     image.composite(other, offset, operator=wand.DIFFERENCE_COMPOSITE_OP)
     
     f.write(image.dump(cls.dest_format))
     f.close()
     
     image.destroy()
     other.destroy()
     
     return ExtractedFile(name, EXTRACT_TYPE_DIFF)
示例#2
0
    def difference(cls, prev_image, current_image):
        """
        params are filenames
        """
        print 'diffing', prev_image, current_image

        f, name = cls._get_tmp_file(EXTRACT_TYPE_DIFF)

        print 'Saving diff to', name
        """
        # PIL -- This complains that some pairs of images 'do not match' Even when
        # they are generated from the same PSD and are the same pixel size. WTF.
        # USING IMAGEMAGICK INSTEAD, BITCHES
        p = PILImage.open(prev_image)
        c = PILImage.open(current_image)
        
        diff = ImageChops.difference(c, p)
        
        diff.save(f, cls.dest_format) #TODO catch IOError and do something with it.
        f.close()
        
        del p
        del c
        del diff
        """

        image = Image(current_image)
        other = Image(prev_image)

        isize = image.size
        osize = other.size

        offset = (0, 0)
        if isize != osize:
            #enabling this makes the diff always the same size as the largest one
            #disabling makes it the size of the most current one. Hopefully this doesnt
            #happen very often...
            if False:  #isize < osize: #basically, if both x and y components are less
                #swap; image is always the larger one
                tmp = image
                image = other
                other = tmp

                tmp = isize
                isize = osize
                osize = tmp

            offset = ((isize[0] - osize[0]) / 2, (isize[1] - osize[1]) / 2)

        image.composite(other, offset, operator=wand.DIFFERENCE_COMPOSITE_OP)

        f.write(image.dump(cls.dest_format))
        f.close()

        image.destroy()
        other.destroy()

        return ExtractedFile(name, EXTRACT_TYPE_DIFF)
示例#3
0
def convert(source_fh, source_type, dest_type, dest_size):
    """somewhat like convert(1)"""
    i = Image(source_fh, source_type)

    if not i.select(dest_size):
        print "bad size"
        i.alpha(True)
        i.scale(dest_size)

    i.alpha(True)
    result = i.dump(dest_type)

    return result