Skip to content

Commit

Permalink
Tickets - FS-7947 and FS-6057 (#74)
Browse files Browse the repository at this point in the history
* Add some transformation functions for the ticket FS-7947 and FS-6057

* Add some transformation functions for the ticket FS-7947 and FS-6057

* Add some transformation functions for the ticket FS-7947 and FS-6057
  • Loading branch information
naiyercels authored May 14, 2024
1 parent cb0c3d5 commit cf123d3
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 2 deletions.
11 changes: 11 additions & 0 deletions examples/animate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from filestack import Client, Security

# create security object
json_policy = {"expiry":1717101000,"call":["pick","read","stat","write","writeUrl","store","convert"]}
security = Security(json_policy, '<YOUR_APP_SECRET>')
APIKEY = '<YOUR_API_KEY>'

client = Client(apikey=APIKEY, security=security)
transform = client.transform_external('/animate=fit:scale,width:200,height:300/[<HANDLER1>,<HANDLER2>]')
transform.animate(fit='scale',width=200,height=300,loop=0,delay=1000)
print(transform.url)
12 changes: 12 additions & 0 deletions examples/convert_pdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from filestack import Client, Security

# create security object
json_policy = {"call":["pick","read","stat","write","writeUrl","store","convert"],"expiry":1717099200}
security = Security(json_policy, '<YOUR_APP_SECRET>')
APIKEY = '<YOUR_API_KEY>'

client = Client(apikey=APIKEY, security=security)
transform = client.transform_external('pdfconvert=pageorientation:landscape/HANDLER')
transform.pdf_convert(pageorientation='landscape', pageformat='a4', metadata=True)
print(transform.url)

12 changes: 12 additions & 0 deletions examples/createpdf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from filestack import Client, Security

# create security object
json_policy = {"call":["pick","read","stat","write","writeUrl","store","convert"],"expiry":1717099200}
security = Security(json_policy, '<YOUR_APP_SECRET>')
APIKEY = '<YOUR_API_KEY>'

client = Client(apikey=APIKEY, security=security)
transform = client.transform_external('/pdfcreate/[<HANDLER1>,<HANDLER2>]')
transform.pdfcreate(engine='mupdf')
print(transform.url)

11 changes: 11 additions & 0 deletions examples/doc_to_image.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from filestack import Client, Security

# create security object
json_policy = {"call":["pick","read","stat","write","writeUrl","store","convert"],"expiry":1717099200}
security = Security(json_policy, '<YOUR_APP_SECRET>')
APIKEY = '<YOUR_API_KEY>'

client = Client(apikey=APIKEY, security=security)
transform = client.transform_external('/doc_to_images/<HANDLE>')
transform.doc_to_images(pages=[1], engine='imagemagick', format='png', quality=100, density=100, hidden_slides=False)
print(transform.url)
11 changes: 11 additions & 0 deletions examples/fallback.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from filestack import Client, Security

# create security object
json_policy = {"call":["pick","read","stat","write","writeUrl","store","convert"],"expiry":1717099200}
security = Security(json_policy, '<YOUR_APP_SECRET>')
APIKEY = '<YOUR_API_KEY>'

client = Client(apikey=APIKEY, security=security)
transform = client.transform_external('/')
transform.fallback(file='HANDLER', cache=12)
print(transform.url)
11 changes: 11 additions & 0 deletions examples/smart_crop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from filestack import Client, Security

# create security object
json_policy = {"call":["pick","read","stat","write","writeUrl","store","convert"],"expiry":1717099200}
security = Security(json_policy, '<YOUR_APP_SECRET>')
APIKEY = '<YOUR_API_KEY>'

client = Client(apikey=APIKEY, security=security)
transform = client.transform_external('/smart_crop=width:100,height:100/HANDLER')
transform.smart_crop(width=100, height=100)
print(transform.url)
16 changes: 14 additions & 2 deletions filestack/mixins/imagetransformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ def quality(self, value=None):
def zip(self):
return self._add_transform_task('zip', locals())

def fallback(self, handle=None, cache=None):
def fallback(self, file=None, cache=None):
return self._add_transform_task('fallback', locals())

def pdf_info(self, colorinfo=None):
return self._add_transform_task('pdfinfo', locals())

def pdf_convert(self, pageorientation=None, pageformat=None, pages=None):
def pdf_convert(self, pageorientation=None, pageformat=None, pages=None, metadata=None):
return self._add_transform_task('pdfconvert', locals())

def minify_js(self, gzip=None, use_babel_polyfill=None, keep_fn_name=None, keep_class_name=None,
Expand Down Expand Up @@ -153,6 +153,18 @@ def av_convert(self, *, preset=None, force=None, title=None, extname=None, filen
def auto_image(self):
return self._add_transform_task('auto_image', locals())

def doc_to_images(self, pages=None, engine=None, format=None, quality=None, density=None, hidden_slides=None):
return self._add_transform_task('doc_to_images', locals())

def smart_crop(self, mode=None, width=None, height=None, fill_color=None, coords=None):
return self._add_transform_task('smart_crop', locals())

def pdfcreate(self, engine=None):
return self._add_transform_task('pdfcreate', locals())

def animate(self, delay=None, loop=None, width=None, height=None, fit=None, align=None, background=None):
return self._add_transform_task('animate', locals())

def _add_transform_task(self, transformation, params):
if isinstance(self, filestack.models.Transformation):
instance = self
Expand Down
47 changes: 47 additions & 0 deletions tests/tasks_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import re

import pytest
import responses

from filestack import Transformation, AudioVisual
from filestack import config

APIKEY = 'SOMEAPIKEY'
HANDLE = 'SOMEHANDLE'
EXTERNAL_URL = 'SOMEEXTERNALURL'


@pytest.fixture
def transform():
return Transformation(apikey=APIKEY, external_url=EXTERNAL_URL)


def test_createpdf(transform):
target_url = '{}/{}/pdfcreate/{}/[v7MSSKswR0mvEwZS9LD0,Sr5CrtQPSs5TTZzor1Cw]'.format(config.CDN_URL, APIKEY, EXTERNAL_URL)
obj = transform.pdfcreate(engine='mupdf')
assert obj.url

def test_animate(transform):
target_url = '{}/{}/animate=fit:scale,width:200,height:300/{}/[OjKeBAuBTIWygi1NE8fx,WTY6jjIaTPOvWY9KsNh9]'.format(config.CDN_URL, APIKEY, EXTERNAL_URL)
obj = transform.animate(fit='scale',width=200,height=300,loop=0,delay=1000)
assert obj.url

def test_doc_to_images(transform):
target_url = '{}/{}/doc_to_images/{}/3zOWSOLQ0SEdphqVil9Q'.format(config.CDN_URL, APIKEY, EXTERNAL_URL)
obj = transform.doc_to_images(pages=[1], engine='imagemagick', format='png', quality=100, density=100, hidden_slides=False)
assert obj.url

def test_smart_crop(transform):
target_url = '{}/{}/smart_crop=width:100,height:100/{}/v7MSSKswR0mvEwZS9LD0'.format(config.CDN_URL, APIKEY, EXTERNAL_URL)
obj = transform.smart_crop(width=100, height=100)
assert obj.url

def test_pdf_convert(transform):
target_url = '{}/{}/pdfconvert=pageorientation:landscape/{}/3zOWSOLQ0SEdphqVil9Q'.format(config.CDN_URL, APIKEY, EXTERNAL_URL)
obj = transform.pdf_convert(pageorientation='landscape', pageformat='a4', metadata=True)
assert obj.url

def test_fallback(transform):
target_url = '{}/{}/{}'.format(config.CDN_URL, APIKEY, EXTERNAL_URL)
obj = transform.fallback(file='3zOWSOLQ0SEdphqVil9Q', cache=12)
assert obj.url

0 comments on commit cf123d3

Please sign in to comment.