Example #1
0
    def encrypt(self, width, height, smart, adaptive, full, fit_in,
                flip_horizontal, flip_vertical, halign, valign, trim,
                crop_left, crop_top, crop_right, crop_bottom, filters, image):

        generated_url = Url.generate_options(width=width,
                                             height=height,
                                             smart=smart,
                                             meta=False,
                                             adaptive=adaptive,
                                             full=full,
                                             fit_in=fit_in,
                                             horizontal_flip=flip_horizontal,
                                             vertical_flip=flip_vertical,
                                             halign=halign,
                                             valign=valign,
                                             trim=trim,
                                             crop_left=crop_left,
                                             crop_top=crop_top,
                                             crop_right=crop_right,
                                             crop_bottom=crop_bottom,
                                             filters=filters)

        url = "%s/%s" % (generated_url, hashlib.md5(image).hexdigest())

        def pad(s):
            return s + (16 - len(s) % 16) * "{"

        cipher = AES.new(self.security_key)
        encrypted = base64.urlsafe_b64encode(
            cipher.encrypt(pad(url.encode('utf-8'))))

        return encrypted
Example #2
0
    def test_can_generate_url(self):
        url = Url.generate_options(
            debug=True,
            width=300,
            height=200,
            smart=True,
            meta=True,
            trim=True,
            adaptive=True,
            full=True,
            fit_in=True,
            horizontal_flip=True,
            vertical_flip=True,
            halign="left",
            valign="top",
            crop_left=100,
            crop_top=100,
            crop_right=400,
            crop_bottom=400,
            filters="brightness(100)",
        )

        expect(url).to_equal(
            "debug/meta/trim/100x100:400x400/adaptive-full-fit-in/-300x-200/left/top/smart/filters:brightness(100)"
        )
Example #3
0
    def test_can_generate_url(self):
        url = Url.generate_options(
            debug=True,
            width=300,
            height=200,
            smart=True,
            meta=True,
            trim=True,
            adaptive=True,
            full=True,
            fit_in=True,
            horizontal_flip=True,
            vertical_flip=True,
            halign="left",
            valign="top",
            crop_left=100,
            crop_top=100,
            crop_right=400,
            crop_bottom=400,
            filters="brightness(100)",
        )

        expect(url).to_equal(
            "debug/meta/trim/100x100:400x400/adaptive-full-fit-in/-300x-200/left/top/smart/filters:brightness(100)"
        )
Example #4
0
    def test_can_generate_url(self):
        url = Url.generate_options(
            debug=True,
            width=300,
            height=200,
            smart=True,
            meta=True,
            trim=True,
            adaptive=True,
            full=True,
            fit_in=True,
            horizontal_flip=True,
            vertical_flip=True,
            halign="left",
            valign="top",
            crop_left=100,
            crop_top=100,
            crop_right=400,
            crop_bottom=400,
            auth=
            "requester(CVZzFCbz4Rcf2Lmu9mvtC1CmvPukHy5kS2LNtNaBFM2N):contract(Du2kswW2h1gNVnTWdfNdSxBrC2F9ofoaZsXA6ki1PhG6):document(profile):field(avatarURL):owner(8vagK6r9BnYct3k8WWYXNFadY1hG8TjikR3SfXceFnRQ):updatedAt(1602042152761)",
            filters="brightness(100)",
        )

        expect(url).to_equal(
            "debug/meta/trim/100x100:400x400/adaptive-full-fit-in/-300x-200/left/top/smart/auth:requester(CVZzFCbz4Rcf2Lmu9mvtC1CmvPukHy5kS2LNtNaBFM2N):contract(Du2kswW2h1gNVnTWdfNdSxBrC2F9ofoaZsXA6ki1PhG6):document(profile):field(avatarURL):owner(8vagK6r9BnYct3k8WWYXNFadY1hG8TjikR3SfXceFnRQ):updatedAt(1602042152761)/filters:brightness(100)"
        )
Example #5
0
    def encrypt(self,
                width,
                height,
                smart,
                adaptive,
                full,
                fit_in,
                flip_horizontal,
                flip_vertical,
                halign,
                valign,
                trim,
                crop_left,
                crop_top,
                crop_right,
                crop_bottom,
                filters,
                image):

        generated_url = Url.generate_options(
            width=width,
            height=height,
            smart=smart,
            meta=False,
            adaptive=adaptive,
            full=full,
            fit_in=fit_in,
            horizontal_flip=flip_horizontal,
            vertical_flip=flip_vertical,
            halign=halign,
            valign=valign,
            trim=trim,
            crop_left=crop_left,
            crop_top=crop_top,
            crop_right=crop_right,
            crop_bottom=crop_bottom,
            filters=filters
        )

        url = "%s/%s" % (generated_url, hashlib.md5(image).hexdigest())

        def pad(s):
            return s + (16 - len(s) % 16) * "{"

        cipher = AES.new(self.security_key)
        encrypted = base64.urlsafe_b64encode(cipher.encrypt(pad(url.encode('utf-8'))))

        return encrypted
Example #6
0
    def test_can_generate_url_with_custom_trim(self):
        url = Url.generate_options(debug=True,
                                   width=300,
                                   height=200,
                                   smart=True,
                                   meta=True,
                                   trim='300x200',
                                   adaptive=True,
                                   full=True,
                                   fit_in=True,
                                   horizontal_flip=True,
                                   vertical_flip=True,
                                   halign='left',
                                   valign='top',
                                   crop_left=100,
                                   crop_top=100,
                                   crop_right=400,
                                   crop_bottom=400,
                                   filters='brightness(100)')

        expect(url).to_equal(
            'debug/meta/trim:300x200/100x100:400x400/adaptive-full-fit-in/-300x-200/left/top/smart/filters:brightness(100)'
        )
Example #7
0
    def test_can_generate_url_with_fitin(self):
        url = Url.generate_options(fit_in=True, adaptive=False, full=False)

        expect(url).to_equal('fit-in')
Example #8
0
    def test_can_generate_url_with_defaults(self):
        url = Url.generate_options()

        expect(url).to_be_empty()
Example #9
0
    def test_can_generate_url_with_fitin(self):
        url = Url.generate_options(fit_in=True, adaptive=False, full=False)

        expect(url).to_equal("fit-in")
Example #10
0
    def test_can_generate_url_with_defaults(self):
        url = Url.generate_options()

        expect(url).to_be_empty()