Skip to content

Instantly share code, notes, and snippets.

@mike-engel
Last active October 15, 2015 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-engel/ca8ce68fb5e72af74d55 to your computer and use it in GitHub Desktop.
Save mike-engel/ca8ce68fb5e72af74d55 to your computer and use it in GitHub Desktop.
Generate a responsive image string based on a filename and some widths
function generateResponsiveString (filename, widths, isFallback) {
'use strict'
const urlPrefix = 'https://res.cloudinary.com/beardfury/image/upload/c_scale,w_'
let fullString = ''
if (isFallback) {
return urlPrefix + widths + filename
}
widths.forEach(function (width) {
fullString += urlPrefix + width + filename + ' ' + width + 'w, '
})
// strip the trailing comma and space
return fullString.substr(0, fullString.length - 2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment