Skip to content

Instantly share code, notes, and snippets.

View alankimo's full-sized avatar
🏠
Working from home

Alan K. alankimo

🏠
Working from home
  • Ciudad de México
View GitHub Profile
@alankimo
alankimo / imgURL.js
Created January 18, 2019 21:01 — forked from DanWebb/imgURL.js
Specify a size for a Shopify image asset url. Equivalent to the liquid image size filter: `{{ image | img_url: "medium" }}`
String.prototype.imgURL = function(size) {
// remove any current image size then add the new image size
return this
.replace(/_(pico|icon|thumb|small|compact|medium|large|grande|original|1024x1024|2048x2048|master)+\./g, '.')
.replace(/\.jpg|\.png|\.gif|\.jpeg/g, function(match) {
return '_'+size+match;
})
;
};