Skip to content

Commit 97cba88

Browse files
authored
Merge pull request #52 from imagekit-developer/lqip-raw-parameter
Issue 49 - Lqip doesn't work with restrict unnamed transformation
2 parents 44c53df + 43f0d7a commit 97cba88

File tree

5 files changed

+64
-30
lines changed

5 files changed

+64
-30
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ The `IKImage` component renders an `img` tag. It is used for rendering and manip
178178
| transformationPosition | String |Optional. The default value is `path` that places the transformation string as a URL path parameter. It can also be specified as `query`, which adds the transformation string as the URL's query parameter i.e.`tr`. If you use `src` parameter to create the URL, then the transformation string is always added as a query parameter. |
179179
| queryParameters | Object |Optional. These are the other query parameters that you want to add to the final URL. These can be any query parameters and not necessarily related to ImageKit. Especially useful if you want to add some versioning parameter to your URLs. |
180180
| loading | String |Optional. Pass `lazy` to lazy load images. Note: Component does not accept change in this value after it has mounted. |
181-
| lqip | Object |Optional. You can use this to show a low-quality blurred placeholder while the original image is being loaded e.g. `{active:true, quality: 20, blur: 6`}. The default value of `quality` is `20` and `blur` is `6`. <br /> Note: Component does not accept change in this value after it has mounted.|
181+
| lqip | Object |Optional. You can use this to show a low-quality blurred placeholder while the original image is being loaded e.g. `{active:true, quality: 20, blur: 6, raw: "n-lqip_named_transformation"`}. The default value of `quality` is `20`, and `blur` is `6`. If `raw` transformation is provided, SDK uses that and ignores the `quality` and `blur` parameters. <br /> Note: Component does not accept change in this value after it has mounted.|
182182

183183
### Basic resizing examples
184184

@@ -292,6 +292,7 @@ See the complete list of transformations supported in ImageKit [here](https://do
292292
| effectContrast | e-contrast |
293293
| effectGray | e-grayscale |
294294
| original | orig |
295+
| raw | The string provided in raw will be added in the URL as it is. |
295296

296297
</details>
297298

@@ -366,6 +367,15 @@ By default, the SDK uses the `quality:20` and `blur:6`. You can change this. For
366367
/>
367368
```
368369

370+
You can also specify a `raw` transformation if you want more control over the URL of the low-quality image placeholder. In this case, the SDK ignores `quality` and `blur` parameters.
371+
372+
```js
373+
<IKImage
374+
path="/default-image.jpg"
375+
lqip={{active:true, raw: "n-lqip_named_transformation"}}
376+
/>
377+
```
378+
369379
### Combining lazy loading with low-quality placeholders
370380
You have the option to lazy-load the original image only when the user scrolls near them. Until then, only a low-quality placeholder is loaded. This saves a lot of network bandwidth if the user never scrolls further down.
371381

package-lock.json

Lines changed: 21 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekitio-react",
3-
"version": "1.0.11",
3+
"version": "1.1.0",
44
"description": "React SDK for ImageKit.io which implements client-side upload and URL generation for use inside a react application.",
55
"scripts": {
66
"build": "rm -rf dist*;rollup -c",

src/components/IKImage/index.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class IKImage extends ImageKitComponent {
2020
lqipSrc: lqipSrc,
2121
originalSrcLoaded: false,
2222
intersected: false,
23-
contextOptions : {}
23+
contextOptions: {}
2424
};
2525
}
2626

@@ -45,10 +45,16 @@ class IKImage extends ImageKitComponent {
4545
var quality = parseInt((lqip.quality || lqip.threshold), 10) || 20;
4646
var blur = parseInt((lqip.blur || lqip.blur), 10) || 6;
4747
var newTransformation = options.transformation ? [...options.transformation] : [];
48-
newTransformation.push({
49-
quality,
50-
blur
51-
})
48+
if (lqip.raw && typeof lqip.raw === "string" && lqip.raw.trim() != "") {
49+
newTransformation.push({
50+
raw: lqip.raw.trim()
51+
});
52+
} else {
53+
newTransformation.push({
54+
quality,
55+
blur
56+
})
57+
}
5258
result.lqipSrc = ikClient.url({
5359
...options,
5460
transformation: newTransformation
@@ -128,7 +134,7 @@ class IKImage extends ImageKitComponent {
128134

129135
componentDidMount() {
130136
this.updateImageUrl();
131-
this.setState({ contextOptions : this.getContext() });
137+
this.setState({ contextOptions: this.getContext() });
132138

133139
const image = this.imageRef.current;
134140
const { lqip, loading } = this.props;

tests/jest/IKImage.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,25 @@ describe('IKImage', () => {
173173
expect(ikImage.find('img').prop('src')).toEqual(transformURL);
174174
expect(ikImage.find('img').prop('id')).toEqual('lqip');
175175
});
176+
177+
test("lqip with raw transformation", () => {
178+
const ikImage = shallow(
179+
<IKImage
180+
urlEndpoint={urlEndpoint}
181+
lqip={{ active: true, quality: 50, blur: 25, raw: "n-lqip" }}
182+
path={nestedImagePath}
183+
transformation={[{
184+
named: "thumbnail"
185+
}]}
186+
id="lqip"
187+
/>
188+
);
189+
190+
const transformURL = `${urlEndpoint}/tr:n-thumbnail:n-lqip${nestedImagePath}?${global.SDK_VERSION}`;
191+
expect(ikImage.find('img').prop('src')).toEqual(transformURL);
192+
expect(ikImage.find('img').prop('id')).toEqual('lqip');
193+
});
194+
176195
});
177196

178197
describe('Transformation', () => {

0 commit comments

Comments
 (0)