Ejemplo n.º 1
0
 def test_no_match(self):
     img = self._make_test_image()
     img = make_transparent(img, (130, 160, 120), tolerance=5)
     assert img.mode == 'RGBA'
     assert img.size == (50, 50)
     colors = img.getcolors()
     assert colors == [(1600, (130, 140, 120, 255)), (900, (130, 150, 120, 255))]
Ejemplo n.º 2
0
 def test_from_paletted(self):
     img = self._make_test_image().quantize(256)
     img = make_transparent(img, (130, 150, 120), tolerance=5)
     assert img.mode == 'RGBA'
     assert img.size == (50, 50)
     colors = img.getcolors()
     eq_(colors, [(1600, (130, 140, 120, 255)), (900, (130, 150, 120, 0))])
Ejemplo n.º 3
0
 def test_from_paletted(self):
     img = self._make_test_image().quantize(256)
     img = make_transparent(img, (130, 150, 120), tolerance=5)
     assert img.mode == "RGBA"
     assert img.size == (50, 50)
     colors = img.getcolors()
     assert colors == [(1600, (130, 140, 120, 255)), (900, (130, 150, 120, 0))]
Ejemplo n.º 4
0
 def test_with_color_fuzz(self):
     img = self._make_test_image()
     img = make_transparent(img, (128, 154, 121), tolerance=5)
     assert img.mode == 'RGBA'
     assert img.size == (50, 50)
     colors = img.getcolors()
     assert colors == [(1600, (130, 140, 120, 255)), (900, (130, 150, 120, 0))]
Ejemplo n.º 5
0
 def test_no_match(self):
     img = self._make_test_image()
     img = make_transparent(img, (130, 160, 120), tolerance=5)
     assert img.mode == "RGBA"
     assert img.size == (50, 50)
     colors = img.getcolors()
     assert colors == [(1600, (130, 140, 120, 255)), (900, (130, 150, 120, 255))]
Ejemplo n.º 6
0
 def test_with_color_fuzz(self):
     img = self._make_test_image()
     img = make_transparent(img, (128, 154, 121), tolerance=5)
     assert img.mode == "RGBA"
     assert img.size == (50, 50)
     colors = img.getcolors()
     assert colors == [(1600, (130, 140, 120, 255)), (900, (130, 150, 120, 0))]
Ejemplo n.º 7
0
 def test_from_transparent(self):
     img = self._make_transp_test_image()
     draw = ImageDraw.Draw(img)
     draw.rectangle((0, 0, 4, 4), fill=(130, 100, 120, 0))
     draw.rectangle((5, 5, 9, 9), fill=(130, 150, 120, 255))
     img = make_transparent(img, (130, 150, 120, 120), tolerance=5)
     assert img.mode == 'RGBA'
     assert img.size == (50, 50)
     colors = sorted(img.getcolors(), reverse=True)
     eq_(colors, [(1550, (130, 140, 120, 100)), (900, (130, 150, 120, 0)),
         (25, (130, 150, 120, 255)), (25, (130, 100, 120, 0))])
Ejemplo n.º 8
0
 def test_from_transparent(self):
     img = self._make_transp_test_image()
     draw = ImageDraw.Draw(img)
     draw.rectangle((0, 0, 4, 4), fill=(130, 100, 120, 0))
     draw.rectangle((5, 5, 9, 9), fill=(130, 150, 120, 255))
     img = make_transparent(img, (130, 150, 120, 120), tolerance=5)
     assert img.mode == 'RGBA'
     assert img.size == (50, 50)
     colors = sorted(img.getcolors(), reverse=True)
     eq_(colors, [(1550, (130, 140, 120, 100)), (900, (130, 150, 120, 0)),
                  (25, (130, 150, 120, 255)), (25, (130, 100, 120, 0))])
Ejemplo n.º 9
0
    def get_map(self, query):
        if self.res_range and not self.res_range.contains(query.bbox, query.size, query.srs):
            raise BlankImage()
        if self.coverage and not self.coverage.intersects(query.bbox, query.srs):
            raise BlankImage()
        try:
            resp = self._get_map(query)
            if self.transparent_color:
                resp = make_transparent(resp, self.transparent_color, self.transparent_color_tolerance)
            resp.opacity = self.opacity
            return resp

        except HTTPClientError, e:
            log.warn("could not retrieve WMS map: %s", e)
            reraise_exception(SourceError(e.args[0]), sys.exc_info())
Ejemplo n.º 10
0
 def get_map(self, query):
     if self.res_range and not self.res_range.contains(query.bbox, query.size,
                                                       query.srs):
         raise BlankImage()
     if self.coverage and not self.coverage.intersects(query.bbox, query.srs):
         raise BlankImage()
     try:
         resp = self._get_map(query)
         if self.transparent_color:
             resp = make_transparent(resp, self.transparent_color,
                                     self.transparent_color_tolerance)
         resp.opacity = self.opacity
         return resp
         
     except HTTPClientError, e:
         log.warn('could not retrieve WMS map: %s', e)
         reraise_exception(SourceError(e.args[0]), sys.exc_info())