Last active
December 3, 2019 14:56
-
-
Save Juandresyn/2312392880eb71f1747f6404c6042ac5 to your computer and use it in GitHub Desktop.
Shopify JavaScript Image resize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const imageService = (img, w, h = w) => { | |
| const imgSplit = img.split('.'); | |
| const imgFormat = imgSplit[imgSplit.length - 1]; | |
| const imgFirst = img.split(`.${imgFormat}`)[0]; | |
| return `${imgFirst}_${w}x${h}.${imgFormat}`; | |
| }; | |
| // imageService('https://cdn.shopify.com/s/files/1/0175/8496/t/65/assets/Beckett-Simonon-Oxfords-Durant-Yates-Dean.jpg?1723', 360) | |
| // returns -> "https://cdn.shopify.com/s/files/1/0175/8496/t/65/assets/Beckett-Simonon-Oxfords-Durant-Yates-Dean_360x360.jpg?1723" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment