Skip to content
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

Add support for image trimming #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

tpisani
Copy link

@tpisani tpisani commented Jun 4, 2020

This adds a way to explicitly apply trim options. Another way to apply trimming is to prepend trim/ to the imagePath, but when combined with filters (since trim/ is now considered a part of imagePath) the final generated URL puts the filters before the trim which is not the way Thumbor expects the parameters to be organized causing an error response.

Example of an incorrectly formatted URL:

var Thumbor = require('thumbor')

const t = new Thumbor('KEY', 'http://thumbor.com')

t.setImagePath('trim/http://imgserver.com/image.png').filter('colorize(100,100,100,ffffff)').buildUrl()
// http://thumbor.com/-WBeY7C5iB0GJqFsu1HESfCi7rs=/filters:colorize(100,100,100,ffffff)/trim/http://imgserver.com/image.png

Examples of URLs using trim options:

var Thumbor = require('thumbor')

const t = new Thumbor('KEY', 'http://thumbor.com')

t.setImagePath('http://imgserver.com/image.png')

t.trim().buildUrl()
// http://thumbor.com/TaFyTswL4p1WRg9br4_rVv_hecY=/trim/http://imgserver.com/image.png

t.trim().filter('colorize(100,100,100,ffffff)').buildUrl()
// http://thumbor.com/9usuNQ8OniFoZ54aFf2j-Agmfl4=/trim/filters:colorize(100,100,100,ffffff)/http://imgserver.com/image.png

t.trim('bottom-right').buildUrl()
// http://thumbor.com/7EYHJRUQgH9LdB2e_BA-mzB5nsw=/trim:bottom-right/http://imgserver.com/image.png

t.trim('top-left', 30).buildUrl()
// http://thumbor.com/MMTAuxAU4E6TK79qVSHniOY9t_A=/trim:top-left:30/http://imgserver.com/image.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant