Skip to content

Commit 3914735

Browse files
authored
Merge pull request #415 from cloudinary/feature/add-shortened-AspectRatio
2 parents 84a3ec7 + cfbb2ae commit 3914735

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

__TESTS__/unit/actions/Resize/AspectRatio.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,13 @@ describe('Tests for AspectRatio values Action -- Resize.crop', () => {
3232

3333
expect(url).toContain('ar_1:1,c_crop/ar_16:9,c_crop/ar_4:3,c_crop/ar_3:2,c_crop/ar_3:1,c_crop/ar_5:4,c_crop/c_crop,fl_ignore_aspect_ratio');
3434
});
35+
it('Can use shortened aspectRatio notation', () => {
36+
const url = createNewImage('sample')
37+
.resize(
38+
crop().aspectRatio("3:2"))
39+
.setPublicID('sample')
40+
.toURL();
41+
42+
expect(url).toContain('ar_3:2,c_crop');
43+
});
3544
});

src/actions/resize/ResizeSimpleAction.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {AspectRatioQualifierValue} from "../../qualifiers/aspectRatio/AspectRati
55
import {regionRelative, relative} from "../../qualifiers/flag";
66
import {FlagQualifier} from "../../qualifiers/flag/FlagQualifier";
77
import {ExpressionQualifier} from "../../qualifiers/expression/ExpressionQualifier";
8+
import {AspectRatioType} from "../../types/types";
89

910
/**
1011
* @description Defines a resize using width and height.
@@ -49,10 +50,10 @@ class ResizeSimpleAction extends Action {
4950
* @description Sets the aspect ratio of the asset.
5051
* For a list of supported types see {@link Qualifiers.AspectRatio |
5152
* AspectRatio values}
52-
* @param {number|string} ratio The new aspect ratio, specified as a percentage or ratio.
53+
* @param {AspectRatioType|number|string} ratio The new aspect ratio, specified as a percentage or ratio.
5354
* @return {this}
5455
*/
55-
aspectRatio(ratio: AspectRatioQualifierValue | FlagQualifier | number | string): this {
56+
aspectRatio(ratio: AspectRatioType | AspectRatioQualifierValue | FlagQualifier | number | string): this {
5657
// toFloatAsString is used to ensure 1 turns into 1.0
5758
if (ratio instanceof AspectRatioQualifierValue) {
5859
return this.addQualifier(new Qualifier('ar', ratio));

src/types/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,14 @@ export type ArtisticFilterType =
307307
"frost"|
308308
"zorro";
309309

310+
export type AspectRatioType =
311+
"1:1"|
312+
"5:4"|
313+
"3:1"|
314+
"3:2"|
315+
"4:3"|
316+
"16:9";
317+
310318
export interface LegacyITransforamtionOptions {
311319
transformation?: LegacyITransforamtionOptions | string;
312320
raw_transformation?: string;

0 commit comments

Comments
 (0)