Giter VIP home page Giter VIP logo

imgix.js's Introduction

imgix logo

imgix.js is a dependency-free JavaScript library for the browser that allows for easy integration of imgix into websites.

NPM Version Build Status Monthly Downloads Minified Size License styled with prettier FOSSA Status


Overview / Resources

imgix.js allows developers to easily generate responsive images using the srcset and sizes attributes, or the picture element. This lets you write a single image URL that is parsed and used to make images look great at any screen size, by using imgix to process and resize your images on the fly.

Note: imgix.js is designed to run in the browser, manipulating existing <img> elements on an HTML page. If you're looking for a JavaScript library that can programmatically generate imgix URLs, consider using imgix-core-js instead.

Before getting started with imgix.js, it is highly recommended that you read Eric Portis' seminal article on srcset and sizes. This article explains the history of responsive images in responsive design, why they're necessary, and how all these technologies work together to save bandwidth and provide a better experience for users. The primary goal of imgix.js is to make these tools easier for developers to implement, so having an understanding of how they work will significantly improve your imgix.js experience.

Below are some other articles that help explain responsive imagery, and how it can work alongside imgix:

Installation

There are several ways to install imgix.js. The appropriate method depends on your project.

  1. npm: npm install --save imgix.js
  2. Bower: bower install --save imgix.js
  3. Manual: Download the latest release of imgix.js, and use dist/imgix.js or dist/imgix.min.js.

If your build process will re-run dist/imgix.js or dist/imgix.min.js through Browserify, you'll need to add noParse: [require.resolve('imgix.js')] to your Browserify config. If you skip this, Browserify will attempt to re-require imgix.js' dependencies, which have already been inlined.

Once imgix.js has been included on the page, it will automatically run once, after the DOMContentLoaded event fires. This will detect and process all img, picture, and source tags on the page that are set up to use imgix.js as described in the Usage section of this README.

Configuration

imgix.js has two important global options:

  • host: A string corresponding to the desired imgix hostname (defaults to null). This enables the use of ix-path and ix-params to define images, instead of having to manually provide URLs out in ix-src. See the ix-path and ix-params section below for details.
  • useHttps: A boolean (defaults to true), specifying whether to generate http or https-prefixed URLs.

These configuration options (as well as other options described in the "Advanced Usage" section) can be defined in two ways. The easiest way is to specify them with meta tags in your document's <head>:

<head>
  <meta property="ix:host" content="assets.imgix.net">
  <meta property="ix:useHttps" content="true">
</head>

The other way is to manually set these options on the imgix.config object. Note that these options should be set after loading imgix.js, but before the DOMContentLoaded event is fired on the page:

<script src="imgix.js"></script>
<script>
  imgix.config.host = 'assets.imgix.net';
  imgix.config.useHttps = false;
</script>

Usage

After installation and set up are complete, one can begin adding responsive images to the page through one of few ways:

ix-src

Creates an img tag with the ix-src attribute:

<img
  ix-src="https://assets.imgix.net/unsplash/hotairballoon.jpg?w=300&h=500&fit=crop&crop=right"
  alt="A hot air balloon on a sunny day"
  sizes="100vw"
>

Please note: 100vw is an appropriate sizes value for a full-bleed image. If your image is not full-bleed, you should use a different value for sizes. Eric Portis' "Srcset and sizes" article goes into depth on how to use the sizes attribute.

This will generate HTML something like the following:

<img
  ix-src="https://assets.imgix.net/unsplash/hotairballoon.jpg?w=300&h=500&fit=crop&crop=right"
  alt="A hot air balloon on a sunny day"
  sizes="100vw"
  srcset="
    https://assets.imgix.net/unsplash/hotairballoon.jpg?w=100&h=167&fit=crop&crop=right 100w,
    https://assets.imgix.net/unsplash/hotairballoon.jpg?w=200&h=333&fit=crop&crop=right 200w,

    https://assets.imgix.net/unsplash/hotairballoon.jpg?w=2560&h=4267&fit=crop&crop=right 2560w
  "
  src="https://assets.imgix.net/unsplash/hotairballoon.jpg?w=300&h=500&fit=crop&crop=right"
  ix-initialized="ix-initialized"
>

Since imgix can generate as many derivative resolutions as needed, imgix.js calculates them programmatically, using the dimensions you specify (note that the w and h params scale appropriately to maintain the correct aspect ratio). All of this information has been placed into the srcset and sizes attributes. Because of this, imgix.js no longer needs to watch or change the img tag, as all responsiveness will be handled automatically by the browser as the page is resized.

ix-path and ix-params

If configured with a global host option, imgix.js can use the ix-path and ix-params attributes instead of ix-src. The ix-path attribute is used to specify the path to an image, and the ix-params attribute is used to define the imgix URL API parameters to be applied to the image. Using these two attributes instead of ix-src has several advantages:

  1. ix-params automatically URL/Base64-encodes specified parameters, as appropriate.
  2. ix-params is a JSON string, which is easier to read than a URL and can be generated by other tools if necessary.
  3. Not having to re-type https://my-source.imgix.net helps keep code DRY.

Here's how the previous example would be written out using ix-path and ix-params instead of ix-src. Regardless of the method chosen, the end result in-browser will be the same.

<img
  ix-path="unsplash/hotairballoon.jpg"
  ix-params='{
    "w": 300,
    "h": 500,
    "fit": "crop",
    "crop": "right"
  }'
  alt="A hot air balloon on a sunny day"
>

Please note: ix-params must be a valid JSON string. This means that keys and string values must be surrounded by double quotes, e.g., "fit": "crop".

ix-sizes attribute

When set to auto, automatically updates an img tag's sizes attribute to match the image's display size.

<img
  ix-src="https://assets.imgix.net/unsplash/hotairballoon.jpg?w=300&h=500&fit=crop&crop=right"
  alt="A hot air balloon on a sunny day"
  ix-sizes="auto"
>

Please note: the image width has to be calculable before the image has loaded, otherwise sizes will not match the width of the displayed image. In most cases, using the CSS rule img[ix-sizes="auto"] { display: block; width: 100%; } will ensure the image's width is calculable before it has loaded.

Generates HTML similar to the following

<img
  ix-src="https://assets.imgix.net/unsplash/hotairballoon.jpg?w=300&h=500&fit=crop&crop=right"
  alt="A hot air balloon on a sunny day"
  ix-sizes="auto"
  sizes="200px"
  srcset="
    https://assets.imgix.net/unsplash/hotairballoon.jpg?w=100&h=167&fit=crop&crop=right 100w,
    https://assets.imgix.net/unsplash/hotairballoon.jpg?w=200&h=333&fit=crop&crop=right 200w,

    https://assets.imgix.net/unsplash/hotairballoon.jpg?w=2560&h=4267&fit=crop&crop=right 2560w
  "
  src="https://assets.imgix.net/unsplash/hotairballoon.jpg?w=300&h=500&fit=crop&crop=right"
  ix-initialized="ix-initialized"
>

When using ix-sizes="auto", the browser will not have the sizes attribute to reference on first render but only after imgix.js has loaded. This is why it's recommended to manually set sizes whenever possible.

picture tags

If an art-directed image is desired, imgix.js plays nicely with the picture tag. This allows for specifying more advanced responsive images, by changing properties such as the crop and aspect ratio for different screens. To get started, construct a picture tag with a source attribute for each art-directed image, and a fallback img tag. If new to using the picture tag, consider reading our tutorial to learn more about how it works.

The source tags can be used with ix-src or ix-path and ix-params, just like img tags. The following example will generate HTML that displays Bert and Ernie on small screens, just Bert on medium-sized screens, and just Ernie on large screens.

<picture>
  <source
    media="(min-width: 880px)"
    sizes="430px"
    ix-path="imgixjs-demo-page/bertandernie.jpg"
    ix-params='{
      "w": 300,
      "h": 300,
      "fit": "crop",
      "crop": "left"
    }'
  >
  <source
    media="(min-width: 640px)"
    sizes="calc(100vw - 20px - 50%)"
    ix-path="imgixjs-demo-page/bertandernie.jpg"
    ix-params='{
      "w": 300,
      "h": 300,
      "fit": "crop",
      "crop": "right"
    }'
  >
  <source
    sizes="calc(100vw - 20px)"
    ix-path="imgixjs-demo-page/bertandernie.jpg"
    ix-params='{
      "w": 300,
      "h": 100,
      "fit": "crop"
    }'
  >
  <img ix-path="imgixjs-demo-page/bertandernie.jpg">
</picture>

Advanced Usage

Overriding ix-host

When displaying images between multiple imgix Sources, the host option can be overridden on any img or source tag by specifying an ix-host attribute in the tag:

<img
  ix-host="a-different-source.imgix.net"
  ix-path="unsplash/hotairballoon.jpg"
  ix-params='{
    "w": 300,
    "h": 500,
    "fit": "crop",
    "crop": "right"
  }'
  alt="A hot air balloon on a sunny day"
>

Disabling auto-initialization

By default, imgix.js will automatically run as soon as the DOMContentLoaded event fires, immediately processing all img and source tags on the page that are set up to use imgix.js. This auto-initialization behavior can be disabled by including the following meta tag in the document's head:

<head>
  <meta property="ix:autoInit" content="false">
</head>

Manually initializing imgix.js

If auto-initialization is disabled as described above, imgix.js will need to be run manually in order to process the img and source tags on the page. This can be done by invoking imgix.init().

When calling imgix.init(), a map of options can be passed in to override the global configuration settings. For example:

imgix.init({
  useHttps: false,
  host: 'a-different-source.imgix.net'
});

imgix.init() idempotency

Whether imgix.init() is run automatically when the DOMContentLoaded event fires or manually initialized, it will always be idempotent. This means that img and source tags that have already been processed by imgix.js will not be re-processed by subsequent calls.

However, if you would like to re-process all imgix.js-ready img and source tags, you can override the function's idempotency by calling imgix.init() again and passing in the force: true option:

imgix.init({
  force: true
})

Lazy Loading With lazysizes

If lazy loading images is desired, we recommend using lazysizes. In order to use imgix.js with lazysizes, add class=lazyload to your image and generate images using lazysizes-compatible attributes instead of the standard src, srcset, and sizes by changing some configuration settings:

Using <meta> tags:

<head>
  <meta property="ix:srcAttribute" content="data-src">
  <meta property="ix:srcsetAttribute" content="data-srcset">
  <meta property="ix:sizesAttribute" content="data-sizes">
</head>

Using JavaScript:

imgix.config.srcAttribute = 'data-src';
imgix.config.srcsetAttribute = 'data-srcset';
imgix.config.sizesAttribute = 'data-sizes';

Image Tag Example:

<img
  ix-src="https://assets.imgix.net/unsplash/hotairballoon.jpg?w=300&h=500&fit=crop&crop=right"
  alt="A hot air balloon on a sunny day"
  sizes="100vw"
  class="lazyload"
>

If lazy loading is required for some images but undesirable for others, we provide the optional class nolazyload to disable lazy loading on select assets.

Image Tag Example:

<img
  ix-src="https://assets.imgix.net/unsplash/hotairballoon.jpg?w=300&h=500&fit=crop&crop=right"
  alt="A hot air balloon on a sunny day"
  sizes="100vw"
  class="nolazyload"
>

Custom Input Attributes

imgix.js defaults to pulling its data from the ix-src, ix-path, ix-params, and ix-host attributes. If custom input attributes are desired, they can be specified by changing some configuration settings. This can be useful if, say, there is a concern about W3C compliance.

Using <meta> tags:

<head>
  <meta property="ix:srcInputAttribute" content="data-ix-src">
  <meta property="ix:pathInputAttribute" content="data-ix-path">
  <meta property="ix:paramsInputAttribute" content="data-ix-params">
  <meta property="ix:hostInputAttribute" content="data-ix-host">
</head>

Using JavaScript:

imgix.config.srcInputAttribute = 'data-ix-src';
imgix.config.pathInputAttribute = 'data-ix-path';
imgix.config.paramsInputAttribute = 'data-ix-params';
imgix.config.hostInputAttribute = 'data-ix-host';

Null Output Attributes

In rare cases, it may be undesirable to have imgix.js modify the src, srcset, or sizes attributes of the <img> elements it's targeting. In such cases, the default behavior can be overridden by setting some configuration values to null:

Using <meta> tags:

<head>
  <meta property="ix:srcAttribute" content="">
  <meta property="ix:srcsetAttribute" content="">
  <meta property="ix:sizesAttribute" content="">
</head>

Using JavaScript:

imgix.config.srcAttribute = null;
imgix.config.srcsetAttribute = null;
imgix.config.sizesAttribute = null;

Base-64 encoded parameters

All of imgix's API parameters can be provided as Base64 variants. This is especially useful when providing text for the txt parameter, or URLs for parameters such as mark or blend.

When providing parameters via the ix-params attribute, note that the values for any Base64 variant parameters will be automatically base64-encoded by imgix.js, and can therefore be provided unencoded.

<img
  ix-path="unsplash/hotairballoon.jpg"
  ix-params='{
    "txt64": "Hello, World!"
  }'
  alt="A hot air balloon on a sunny day"
>

When providing a URL with parameters via the ix-src attribute, note that the values for any Base64 variant parameters will not be automatically base64-encoded by imgix.js.

<img
  ix-src="https://assets.imgix.net/unsplash/hotairballoon.jpg?txt64=SGVsbG8sIFdvcmxkIQ"
  alt="A hot air balloon on a sunny day"
  sizes="100vw"
>

Default parameters

If a default set of parameters are desired, they can be extracted out into a global config using imgix.defaultParameters. These settings will become the default paramters for each imgix tag globally, before any specific parameters are loaded from ix-params or ix-src

// setup
imgix.config.defaultParams = {
	auto: 'format,compress',
	fit: 'crop'
}

// later
<img
  ix-path="hero.png"
  ix-params='{"fit":"clip"}'
>

// becomes
<img src=".../hero.png?auto=format,compress&fit=clip">

What is the ixlib param?

For security and diagnostic purposes, we default to signing all requests with the language and version of library used to generate the URL. This can be disabled by setting the includeLibraryParam configuration option to false.

Using a <meta> tag:

<head>
  <meta property="ix:includeLibraryParam" content="false">
</head>

Using JavaScript:

imgix.config.includeLibraryParam = false;

Browser Support

  • By default, browsers that don't support srcset, sizes, or picture will gracefully fall back to the default img src when appropriate. If you want to provide a fully-responsive experience for these browsers, imgix.js works great alongside Picturefill!
  • If using Base64 variant params and require IE <= 9 support, we recommend using a polyfill for atob/btoa, such as Base64.js.

Meta

imgix.js was made by imgix. It's licensed under the BSD 2-Clause license (see the license file for more info). Any contribution is absolutely welcome, but please review the contribution guidelines before getting started.

License

FOSSA Status

imgix.js's People

Contributors

0xflotus avatar alessbell avatar arno-fukuda avatar atlawrie avatar bubble-bub avatar fossabot avatar frederickfogerty avatar heyitsbryanm avatar ivanseidel avatar jacktasia avatar jayeb avatar jordanthomas avatar joshfrench avatar kellysutton avatar longevitytina avatar luqven avatar matiasnombarasco avatar paulstraw avatar pedroaguilar avatar psfrankie avatar rakuista avatar renovate-bot avatar renovate[bot] avatar sherwinski avatar zacman85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imgix.js's Issues

Publish to npm?

Any reason this hasn't been published to npm yet? It works fine in my node project fetching from GitHub, but I'm missing out on npm's versioning features and performance.

allow cleaning up of FluidSet

right now there is no way to destroy the FluidSet object created by imgix.fluid() this causing memory leaks once the image is removed from the DOM tree.

Images in fixed position are not detected

Noticed that images that are in fixed position or when their parents are in fixed position imgix does not pick up the image.

Tried with data-src attribute where the element itself was in fixed position and was given a height.

Another situation is when the parent was in fixed position and the element was a img with a position of relative.

In both cases the imgix.js would not detect the images.

[React] Images not loading until screen resize.

Hello imgix.js

With React, I am using imgix to display a background photo in this way

<div
  className="photo imgix-fluid"
  data-src={"https:" + image + "?auto=format&fit=clamp&crop=entropy"}
  />

with the class

.photo {
  background-position: 50% 50%;
  background-size: cover;
} 

The page loads fully, but without the images. The images then load when I resize the viewport by 1px+.

I believe this is due to conflicts between the virtual DOM of React & imgix writing to the DOM.

Any ideas?

Imgix.js with Angular?

I'm running into the problem where Imgix isn't converting the data-src url to src. I think it's because I'm using angular. Any idea how to integrate? I see you have a React library but not one for Angular :)

Using console blindly breaks IE <= 9

There are some console.log/warn statements throughout the code that should never be fired in production without ensuring the console exists or defining a noop or something in place of it.

console isn't defined in IE <= 9 unless it's actually open at the time: http://caniuse.com/#search=console

This is problematic when there are other params that imgix doesn't recognize or a new param like ch

Question: How do I generate secure URLs from the client JS library?

I'd like to use imgix in our app and generate secure urls so that users don't tamper with the image url. Maybe I missed it but I don't see anything about secure URLs on the client js library. I can see how we generate that on the admin side but I will need to generate them on the fly in the application.

Any ideas?

Significant amount of processing time spent in urlParser

Trying to get to the bottom of some scroll jank I noticed that imgix.js library spends a lot of time processing during scroll even after all images have been loaded.

imgix.js processing time

We have since increased our throttle timeout from the default 200ms to 2000ms, which has decreased the amount of time spent in urlParser.

How to apply imgix-js on command?

http://stackoverflow.com/questions/30444716/how-to-apply-imgix-js-on-command


$(document).ready(function () {
    var imgixOptions = {
        updateOnResizeDown : true,
        updateOnPinchZoom : true,
        fitImgTagToContainerWidth: true,
        fitImgTagToContainerHeight: true,
        autoInsertCSSBestPractices: true,
        pixelStep : 5
    };

    imgix.onready(function() {
        imgix.fluid(imgixOptions);
    });
});

This works as expected on dom ready however some pieces of my site load dynamically using AJAX.

How can I trigger the imgix-js library to load the images the way it does on dom ready?

An element that is imgix fluid, and has `display:none` initially, does not get the image updated once it is shown

So a little background, we want to be able to hide on element and show another element for a test, but using a display: none on the original element, prevents the imgix.js from applying the fluid image for that element. As a result, when that element is shown, it doesn't have the actual image attached.

Resizing the window forces the call to get the image, but I don't see any documentation to force a "refresh", or anything to have it show after being display: none. Our current workaround is to have it be height 0 and visibility hidden, but that seems like a bad hack.

Any input on this would be great! Here's a gif to illustrate:

image

Dynamically changing the data-src attribute

I'm using Meteor JS which is dynamically changing the value of the data-src attribute of my image container. My problem is that imgix isn't picking up the changes. Even if I re-run imgix.fluid(); after changing the data-src, the src attribute isn't updated.

It works fine if I directly set the src attribute, but I would like to use imgix.fluid();.

Information on how width is set

For some of our images, imgix is requesting an image with a height but not a width, which is resulting in very large images, in some cases larger than the original.

I haven't yet been able to reduce what I'm working with into a contained example but could you point me to either documentation or the source code of interest where the query strings are being calculated?

Thanks.

Properly handle `crossorigin` attribute on images

Right now, because we proxy image-loading in the imgix.setElementImageAfterLoad method, we're not respecting the crossorigin attribute on images. This can result in duplicate requests when the "cached" image is applied to the <img/> element.

Extracting BG image when there are parentheses in the image URL

We have an old user generated image that has a (3) in the filename. Why? No idea haha (we've since taken to renaming images so this doesn't happen, but we're still left with older images that potentially have weird characters in them).

If we're using that image as a background image, the parentheses break the CSS attribute, because it escapes the style early:

<div style="background-image: url(https://images.unsplash.com/some-photo(3)-something-else);"></div>

So to fix it, we could wrap the background-image style attribute in parentheses but that seems to break the imgix.js getRawBackgroundImage regex.

You can see the specific image here: https://unsplash.com/photos/4uCSqP5OKiI (it's broken)

Any way we could update the regex to account for parentheses?

Thanks.

Dpr detection when swapping screens

http://codepen.io/anon/pen/MazvMB

When you move from a dpr1 screen to a dpr 2 screen and trigger a new image via resize, you get the correct dpr 2 value being appended. When moving back to a dpr 1 screen from the dpr 2 screen, it remains a dpr2 value. See attached codepen. This relates directly to ticket #4123 in zendesk.

onLoad callback timing

In Safari I'm seeing some weird behavior where fluid is creating two requests to Imgix for each image. One for the "preload" and one when the target element src is updated. It doesn't always happen, it appears tied to caching in some capacity.

The callback is fired once the "preload" image onload occurs, but in the scenario I'm describing the image isn't actually done loading at this point.

Boiling it down – the onload callback fires too early in some cases in Safari.

Here's a fiddle that should demonstrate the Safari behavior:
https://jsfiddle.net/6vtr8bjg/

Lazy Load Response Lag

There appears to be a bit of lag in response to the lazy load behavior. Even setting the offset for activation as the entire height of the container, there is a degree of lag in response to the loading of those images.

Update: debounce should be set to 1, or some other faster value by default. It's causing the lag with the default implementation, making it feel unresponsive.

http://codepen.io/miggi/pen/QwejGq

AMD Compatibility

Your md5 implementation leaks as a AMD module when trying to reference imgix with Require.js, which was unexpected. Do you have any plans to make this project AMD compatible?

Push 1.0.21 to NPM

NPM still has v1.0.17, any chance you could push the latest (currently 1.0.21) to NPM when you get a chance? Thanks!

Remove console polyfill

I can't think of a situation where this is needed in a distributed package of imgix.js. (We shouldn't be including any console.log calls, and we currently are not.)

fluid img tag uses height of parent instead of it´s own height

were using imgix fluid with default settings and the following overwritten settings:
imgix.fluid({ "fluidClass": "responsive-image", "lazyLoad": true });

Fluid uses the height of the parent container of an image tag to calculate the width/height of itself.
In my opinion this is a wrong behavior. In our case this causes the image to be extremly large since the parent container is much more bigger than the image tag itself.

Have a look at src/fluid.js on line 152 the parent element is used if the current element is an image tag.
elemSize = imgix.helpers.calculateElementSize(imgix.isImageElement(elem) ? elem.parentNode : elem),

If I negotiate this condition everything is working well with the width/height detection.
elemSize = imgix.helpers.calculateElementSize(!imgix.isImageElement(elem) ? elem.parentNode : elem),

Versioning problem?

Were the last two releases tagged incorrectly?

bower lists these releases:

  - 1.0.18
  - 1.0.17
  - 1.0.16
  - 1.0.15
  - 1.0.14
  - 1.0.13
  - 1.0.12
  - 1.0.11
  - 1.0.10
  - 1.0.9
  - 1.0.8
  - 1.0.7
  - 1.0.6
  - 1.0.5
  - 1.0.4
  - 1.0.3
  - 1.0.2
  - 1.0.1
  - 1.0.0
  - 0.1.20
  - 0.1.19

Note the last two.

bower.json lists 1.0.20 as the current release.

@jacktasia is it possible that the last two releases were tagged as 0.1.19 and 0.1.20 instead of 1.0.19 and 1.0.20?

image

Aspect Ratio Support

Having image parameters pegged to a specific fit dimension such as fitImgTagToContainerHeight or fitImgTagToContainerWidth. It would be nice to pass in a desired image ratio, i.e. 4/3 or 16/9 so that images tied to that fluid object can maintain that ratio no matter what. Currently, this can be accomplished using onChangeParamOverride to manually set the width or height.

Example Here:
http://codepen.io/miggi/pen/CGnKm

display:none bug

When the container of an image is set to display:none and the page is resized, it causes a (potentially large) request of the image set to the width of the window.

Steps to recreate:

  1. Enable imgix.js on an <img> tag
  2. Set display:none to container after image has been loaded in.
  3. Resize page and inspect element to see the large width imgix request.

Test here by uncommenting the display:none in .default class.
http://codepen.io/miggi/pen/CGnKm

Changing an image URL

Question: the URL.autoUpdateImg method refers to a change in the image URL, but it's not clear how I can update the URL of an instance.

In my case I have a single image element for which I'm dynamically setting the src. I'm trying to automatically generate and apply a imgix URL with my desired params whenever I change the source. If I simply update the attribute, the URL is overwritten. I also tried redefining the urlParts.baseUrl property on the instance — same outcome.

My code looks like this:

if (self.imgixPreview) {
  self.$previewElement.attr('src', imgixPath(previewImage.src));
} else {
  self.imgixPreview = new imgix.URL(imgixPath(previewImage.src), {
    q: 90
  });
  self.imgixPreview.attachImageTo('.photos__preview');
  self.imgixPreview.autoUpdateImg('.photos__preview');
}

Images coming from imgix as 1x1

Currently, we're using the imgix library to build URLs. The images are coming back in the correct size, but for some reason the browser thinks the image is only 1x1 Natural when I hover over the link.

Additionally: this only happens on some of our computers.

Any thoughts?

buildUrl strips out port

If a url has a port, the port is not included when getUrl is called.

imageUrl = new imgix.URL('http://localhost:5000/asdf')
imageUrl.getUrl() /* Returns http://localhost/asdf */

I would expect the port to be unchanged.

This will trigger with default images that are not served up through imgix but are being lazy loaded with imgix.js.

Add AMD support

Could you add in the UMD pattern to allow this to load with RequireJS or other loaders?

Respect protocol of request when using .fluid()

When loading a page via HTTPS, and an image "data-src" attribute set without a protocol, (e.g. //example.imgix.net/main-image.png), the image should be loaded with the proper protocol.

Instead, I'm seeing content always loaded via HTTP even from HTTPS pages.

Option to force DPR value using .fluid()

In some cases, we may not want to server higher DPR images, but there is no way to turn this off with .fluid(). Would welcome an option to force DPR settings to stay at 1.

Repository unable to run tests locally upon checkout

Looks like this is due to a missing config.js file.

➜  imgix.js git:(master) ✗ grunt test
Running "test" task
Warning: 

config.js does not exist. Required for tests! (signing)
 Use --force to continue.

Aborted due to warnings.


Execution Time (2015-08-31 23:08:19 UTC)
loading tasks  226ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 97%
test             5ms  ▇▇▇▇ 2%
Total 232ms

Are polyfills really just for IE 8?

The docs mention that polyfills are for IE8, but I see a Promise polyfill. Due to that at least, am I correct in assuming I need polyfills enabled for my build if I want to support IE at all vs just for IE8?

Also, is onready needed at all if you place imgix.js or at least the initialization code, at the end of the body past all images?

Using `fit=crop` with dynamic image source URLs

I've got <img class="imgix-fluid" data-src="{{image.source}}"> and using the following options;

var imgixOptions = {
  pixelStep: 50,
  onChangeParamOverride: function (w, h, o) {
    return {fit: 'crop'};
  }
};

My image source is dynamically generated ({{image.source}}), and may already contain a query string, so I can't easily just add ?fit=crop to the data-src attribute. The problem that this creates is that the image originally loads with a huge height set, and no width; http://path.to/my-image.png?ixjsv=2.1.0&h=1250, which means our users are getting hit with large file sizes right at first. Subsequent image loads seem more predictable, but it would be nice if there was a way to set fit=crop without needing to force it on to the end of the source image URL.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.