Skip to content

Commit 57610a7

Browse files
authored
Merge pull request #60 from imagekit-developer/SDK-94
added e-shadow and e-gradient
2 parents a7b2b19 + 8907702 commit 57610a7

File tree

10 files changed

+82
-67
lines changed

10 files changed

+82
-67
lines changed

.github/workflows/gempush.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ jobs:
1414
uses: ruby/setup-ruby@v1.126.0
1515
with:
1616
ruby-version: 2.6.5
17-
17+
bundler: 2.4.22
1818
- name: Run Test Cases
1919
run: |
20-
gem install bundler
20+
gem install bundler -v 2.4.22
2121
bundle install --jobs 4 --retry 3
2222
bundle exec rake
2323

.github/workflows/test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ jobs:
1313
uses: ruby/setup-ruby@v1.126.0
1414
with:
1515
ruby-version: 2.6.5
16+
bundler: 2.4.22
1617
- name: Build and test with Rake
1718
run: |
18-
gem install bundler
19+
gem install bundler -v 2.4.22
1920
bundle install --jobs 4 --retry 3
2021
bundle exec rake
2122
# - name: Upload code coverage reports to codecov

README.md

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Ruby on Rails gem for [ImageKit](https://imagekit.io/) implements the new APIs a
1313
ImageKit is complete media storage, optimization, and transformation solution that comes with an [image and video CDN](https://imagekit.io/features/imagekit-infrastructure). It can be integrated with your existing infrastructure - storage like AWS S3, web servers, your CDN, and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
1414

1515
Table of contents -
16+
* [Changelog](#changelog)
1617
* [Installation](#installation)
1718
* [Initialization](#initialization)
1819
- [CarrierWave](#carrierwave)
@@ -30,6 +31,13 @@ Table of contents -
3031
# Quick start guide
3132
Get started with [official quick start guide](https://docs.imagekit.io/getting-started/quickstart-guides/ruby-guides) for integrating ImageKit in Ruby on Rails.
3233

34+
## Changelog
35+
### SDK Version 3.0.0
36+
#### Breaking changes
37+
**1. Overlay syntax update**
38+
* In version 3.0.0, we've removed the old overlay syntax parameters for transformations, such as `oi`, `ot`, `obg`, and [more](https://docs.imagekit.io/features/image-transformations/overlay). These parameters are deprecated and will start returning errors when used in URLs. Please migrate to the new layers syntax that supports overlay nesting, provides better positional control, and allows more transformations at the layer level. You can start with [examples](https://docs.imagekit.io/features/image-transformations/overlay-using-layers#examples) to learn quickly.
39+
* You can migrate to the new layers syntax using the `raw` transformation parameter.
40+
3341
## Installation
3442

3543
Add `imagekitio` dependency to your application's Gemfile:
@@ -352,6 +360,29 @@ image_url = imagekit.url({
352360
https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-image,i-ik_canvas,bg-FF0000,w-300,h-100,l-end/img/sample-video.mp4
353361
```
354362

363+
**5. Arithmetic expressions in transformations**
364+
365+
ImageKit allows use of [arithmetic expressions](https://docs.imagekit.io/features/arithmetic-expressions-in-transformations) in certain dimension and position-related parameters, making media transformations more flexible and dynamic.
366+
367+
For example:
368+
369+
```ruby
370+
image_url = imagekit.url({
371+
path: "/default-image.jpg",
372+
url_endpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
373+
transformation: [{
374+
width: "iw_div_4",
375+
height: "ih_div_2",
376+
border: "cw_mul_0.05_yellow"
377+
}]
378+
});
379+
```
380+
381+
**Sample Result URL**
382+
```
383+
https://ik.imagekit.io/your_imagekit_id/default-image.jpg?tr=w-iw_div_4,h-ih_div_2,b-cw_mul_0.05_yellow
384+
```
385+
355386
**List of transformations**
356387

357388
The complete list of transformations supported and their usage in ImageKit can be found [here](https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations). The SDK gives a name to each transformation parameter, making the code simpler, making the code simpler, and readable.
@@ -364,10 +395,10 @@ If you want to generate transformations in your application and add them to the
364395
|-------------------------------|-------------------------|
365396
| height | h |
366397
| width | w |
367-
| aspectRatio | ar |
398+
| aspect_ratio | ar |
368399
| quality | q |
369400
| crop | c |
370-
| cropMode | cm |
401+
| crop_mode | cm |
371402
| x | x |
372403
| y | y |
373404
| focus | fo |
@@ -382,13 +413,15 @@ If you want to generate transformations in your application and add them to the
382413
| lossless | lo |
383414
| trim | t |
384415
| metadata | md |
385-
| colorProfile | cp |
386-
| defaultImage | di |
416+
| color_profile | cp |
417+
| default_image | di |
387418
| dpr | dpr |
388-
| effectSharpen | e-sharpen |
389-
| effectUSM | e-usm |
390-
| effectContrast | e-contrast |
391-
| effectGray | e-grayscale |
419+
| effect_sharpen | e-sharpen |
420+
| effect_usm | e-usm |
421+
| effect_contrast | e-contrast |
422+
| effect_gray | e-grayscale |
423+
| effect_shadow | e-shadow |
424+
| effect_gradient | e-gradient |
392425
| original | orig |
393426
| raw | `replaced by the parameter value` |
394427

lib/active_storage/service/ik_file.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ def updated_at
106106
def extension_status
107107
identifier['extensionStatus']
108108
end
109+
110+
def transformation
111+
identifier['transformation']
112+
end
109113
end
110114
end
111115
end

lib/imagekitio/api_service/file.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def upload(file: nil, file_name: nil, **options)
3636
content_type = options.delete(:content_type) || ''
3737
options = format_to_json(options, :extensions, Array)
3838
options = format_to_json(options, :custom_metadata, Hash)
39+
options = format_to_json(options, :transformation, Hash)
3940
options = validate_upload_options(options || {})
4041
if options.is_a?(FalseClass)
4142
raise ArgumentError, "Invalid Upload option"

lib/imagekitio/constants/file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module File
55

66
VALID_FILE_DETAIL_OPTIONS = ["fileID"]
77

8-
VALID_UPLOAD_OPTIONS = %w[file file_name use_unique_file_name tags folder is_private_file custom_coordinates response_fields extensions webhook_url overwrite_file overwrite_AI_tags overwrite_custom_metadata custom_metadata mime overwrite_tags content_type ]
8+
VALID_UPLOAD_OPTIONS = %w[file file_name use_unique_file_name tags folder is_private_file custom_coordinates response_fields extensions webhook_url overwrite_file overwrite_AI_tags overwrite_custom_metadata custom_metadata mime overwrite_tags content_type transformation ]
99
end
1010
end
1111
end

lib/imagekitio/constants/supported_transformation.rb

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,6 @@ module SupportedTransformation
1818
'rotation': "rt",
1919
'blur': "bl",
2020
'named': "n",
21-
'overlay_image': "oi",
22-
'overlay_image_trim': "oit",
23-
'overlay_image_cropping': "oic",
24-
'overlay_image_quality': "oiq",
25-
'overlay_image_DPR': "oidpr",
26-
'overlay_image_border': "oib",
27-
'overlay_image_background': "oibg",
28-
'overlay_image_aspect_ratio': "oiar",
29-
'overlay_x': "ox",
30-
'overlay_y': "oy",
31-
'overlay_focus': "ofo",
32-
'overlay_height': "oh",
33-
'overlay_width': "ow",
34-
'overlay_text': "ot",
35-
'overlay_text_font_size': "ots",
36-
'overlay_text_font_family': "otf",
37-
'overlay_text_encoded': "ote",
38-
'overlay_text_color': "otc",
39-
'overlay_text_width': "otw",
40-
'overlay_text_background': "otbg",
41-
'overlay_text_padding': "otp",
42-
'overlay_text_inner_alignment': "otia",
43-
'overlay_text_transparency': "oa",
44-
'overlay_alpha': "oa",
45-
'overlay_radius': "or",
46-
'overlay_text_typography': "ott",
47-
'overlay_background': "obg",
4821
'progressive': "pr",
4922
'lossless': "lo",
5023
'trim': "t",
@@ -56,6 +29,8 @@ module SupportedTransformation
5629
'effect_usm': "e-usm",
5730
'effect_contrast': "e-contrast",
5831
'effect_gray': "e-grayscale",
32+
'effect_shadow': "e-shadow",
33+
'effect_gradient': "e-gradient",
5934
'original': "orig",
6035
'raw': 'raw',
6136
}

lib/imagekitio/sdk/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module ImageKitIo
22
module Sdk
3-
VERSION = '2.3.0'
3+
VERSION = '3.0.0'
44
end
55
end

test/imagekit/api_service/file_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,31 @@
228228
expect(@ac[:payload][:fileName]).to eq("fake_name")
229229
expect(upload[:status_code]).to eq(401)
230230
end
231+
232+
it "test_upload_with_valid_expected_success_with_transformation" do
233+
request_obj = double
234+
allow(ImageKitIo::Request)
235+
.to receive(:new)
236+
.with(private_key, public_key, url_endpoint)
237+
.and_return(request_obj)
238+
239+
allow(request_obj)
240+
.to receive(:create_headers)
241+
.and_return({})
242+
@ac={}
243+
allow(request_obj)
244+
.to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}}
245+
.and_return({status_code: 200})
246+
247+
SUT = file_api_service.new(request_obj)
248+
249+
upload = SUT.upload(file: "./fake_file.jpg", file_name: "my_file_name", transformation: { pre: 'l-text,i-Imagekit,fs-50,l-end', post: [{type: 'transformation', value: 'w-100'}]})
250+
251+
expect(@ac[:payload]['transformation']).to eq("{\"pre\":\"l-text,i-Imagekit,fs-50,l-end\",\"post\":[{\"type\":\"transformation\",\"value\":\"w-100\"}]}")
252+
253+
expect(upload[:status_code]).to eq(200)
254+
255+
end
231256
end
232257

233258
describe 'FileListTest' do

test/imagekit/url_test.rb

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -158,32 +158,6 @@
158158
rotation: 90,
159159
blur: 10,
160160
named: "some_name",
161-
overlay_x: 35,
162-
overlay_y: 35,
163-
overlay_focus: "bottom",
164-
overlay_height: 20,
165-
overlay_width: 20,
166-
overlay_image: "/folder/file.jpg",
167-
overlay_image_trim: false,
168-
overlay_image_aspect_ratio: "4:3",
169-
overlay_image_background: "0F0F0F",
170-
overlay_image_border: "10_0F0F0F",
171-
overlay_image_DPR: 2,
172-
overlay_image_quality: 50,
173-
overlay_image_cropping: "force",
174-
overlay_text: "two words",
175-
overlay_text_font_size: 20,
176-
overlay_text_font_family: "Open Sans",
177-
overlay_text_color: "00FFFF",
178-
overlay_text_transparency: 5,
179-
overlay_text_typography: "b",
180-
overlay_background: "00AAFF55",
181-
overlay_text_encoded: "b3ZlcmxheSBtYWRlIGVhc3k%3D",
182-
overlay_text_width: 50,
183-
overlay_text_background: "00AAFF55",
184-
overlay_text_padding: 40,
185-
overlay_text_inner_alignment: "left",
186-
overlay_radius: 10,
187161
progressive: true,
188162
lossless: true,
189163
trim: 5,
@@ -195,12 +169,14 @@
195169
effect_usm: "2-2-0.8-0.024",
196170
effect_contrast: true,
197171
effect_gray: true,
172+
effect_shadow: 'bl-15_st-40_x-10_y-N5',
173+
effect_gradient: 'from-red_to-white',
198174
original: true,
199175
raw: 'w-200,h-200'
200176
},]
201177
}
202178
url = url_obj.generate_url(options)
203-
expect(url).to eq("https://imagekit.io/your-imgekit-id/tr:h-300,w-400,ar-4-3,q-40,c-force,cm-extract,fo-left,f-jpeg,r-50,bg-A94D34,b-5-A94D34,rt-90,bl-10,n-some_name,ox-35,oy-35,ofo-bottom,oh-20,ow-20,oi-folder@@file.jpg,oit-false,oiar-4:3,oibg-0F0F0F,oib-10_0F0F0F,oidpr-2,oiq-50,oic-force,ot-two words,ots-20,otf-Open Sans,otc-00FFFF,oa-5,ott-b,obg-00AAFF55,ote-b3ZlcmxheSBtYWRlIGVhc3k%3D,otw-50,otbg-00AAFF55,otp-40,otia-left,or-10,pr-true,lo-true,t-5,md-true,cp-true,di-folder@@file.jpg,dpr-3,e-sharpen-10,e-usm-2-2-0.8-0.024,e-contrast-true,e-grayscale-true,orig-true,w-200,h-200/default-image.jpg")
179+
expect(url).to eq("https://imagekit.io/your-imgekit-id/tr:h-300,w-400,ar-4-3,q-40,c-force,cm-extract,fo-left,f-jpeg,r-50,bg-A94D34,b-5-A94D34,rt-90,bl-10,n-some_name,pr-true,lo-true,t-5,md-true,cp-true,di-folder@@file.jpg,dpr-3,e-sharpen-10,e-usm-2-2-0.8-0.024,e-contrast-true,e-grayscale-true,e-shadow-bl-15_st-40_x-10_y-N5,e-gradient-from-red_to-white,orig-true,w-200,h-200/default-image.jpg")
204180
end
205181

206182
it "test_generate_url_with_chained_transformation" do

0 commit comments

Comments
 (0)