Skip to content

Commit

Permalink
Merge pull request #60 from imagekit-developer/SDK-94
Browse files Browse the repository at this point in the history
added e-shadow and e-gradient
  • Loading branch information
imagekitio authored Jan 30, 2024
2 parents a7b2b19 + 8907702 commit 57610a7
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gempush.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
uses: ruby/[email protected]
with:
ruby-version: 2.6.5

bundler: 2.4.22
- name: Run Test Cases
run: |
gem install bundler
gem install bundler -v 2.4.22
bundle install --jobs 4 --retry 3
bundle exec rake
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ jobs:
uses: ruby/[email protected]
with:
ruby-version: 2.6.5
bundler: 2.4.22
- name: Build and test with Rake
run: |
gem install bundler
gem install bundler -v 2.4.22
bundle install --jobs 4 --retry 3
bundle exec rake
# - name: Upload code coverage reports to codecov
Expand Down
49 changes: 41 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Ruby on Rails gem for [ImageKit](https://imagekit.io/) implements the new APIs a
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.

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

## Changelog
### SDK Version 3.0.0
#### Breaking changes
**1. Overlay syntax update**
* 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.
* You can migrate to the new layers syntax using the `raw` transformation parameter.

## Installation

Add `imagekitio` dependency to your application's Gemfile:
Expand Down Expand Up @@ -352,6 +360,29 @@ image_url = imagekit.url({
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
```

**5. Arithmetic expressions in transformations**

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.

For example:

```ruby
image_url = imagekit.url({
path: "/default-image.jpg",
url_endpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
transformation: [{
width: "iw_div_4",
height: "ih_div_2",
border: "cw_mul_0.05_yellow"
}]
});
```

**Sample Result URL**
```
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
```

**List of transformations**

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.
Expand All @@ -364,10 +395,10 @@ If you want to generate transformations in your application and add them to the
|-------------------------------|-------------------------|
| height | h |
| width | w |
| aspectRatio | ar |
| aspect_ratio | ar |
| quality | q |
| crop | c |
| cropMode | cm |
| crop_mode | cm |
| x | x |
| y | y |
| focus | fo |
Expand All @@ -382,13 +413,15 @@ If you want to generate transformations in your application and add them to the
| lossless | lo |
| trim | t |
| metadata | md |
| colorProfile | cp |
| defaultImage | di |
| color_profile | cp |
| default_image | di |
| dpr | dpr |
| effectSharpen | e-sharpen |
| effectUSM | e-usm |
| effectContrast | e-contrast |
| effectGray | e-grayscale |
| effect_sharpen | e-sharpen |
| effect_usm | e-usm |
| effect_contrast | e-contrast |
| effect_gray | e-grayscale |
| effect_shadow | e-shadow |
| effect_gradient | e-gradient |
| original | orig |
| raw | `replaced by the parameter value` |

Expand Down
4 changes: 4 additions & 0 deletions lib/active_storage/service/ik_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def updated_at
def extension_status
identifier['extensionStatus']
end

def transformation
identifier['transformation']
end
end
end
end
1 change: 1 addition & 0 deletions lib/imagekitio/api_service/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def upload(file: nil, file_name: nil, **options)
content_type = options.delete(:content_type) || ''
options = format_to_json(options, :extensions, Array)
options = format_to_json(options, :custom_metadata, Hash)
options = format_to_json(options, :transformation, Hash)
options = validate_upload_options(options || {})
if options.is_a?(FalseClass)
raise ArgumentError, "Invalid Upload option"
Expand Down
2 changes: 1 addition & 1 deletion lib/imagekitio/constants/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module File

VALID_FILE_DETAIL_OPTIONS = ["fileID"]

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 ]
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 ]
end
end
end
29 changes: 2 additions & 27 deletions lib/imagekitio/constants/supported_transformation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,6 @@ module SupportedTransformation
'rotation': "rt",
'blur': "bl",
'named': "n",
'overlay_image': "oi",
'overlay_image_trim': "oit",
'overlay_image_cropping': "oic",
'overlay_image_quality': "oiq",
'overlay_image_DPR': "oidpr",
'overlay_image_border': "oib",
'overlay_image_background': "oibg",
'overlay_image_aspect_ratio': "oiar",
'overlay_x': "ox",
'overlay_y': "oy",
'overlay_focus': "ofo",
'overlay_height': "oh",
'overlay_width': "ow",
'overlay_text': "ot",
'overlay_text_font_size': "ots",
'overlay_text_font_family': "otf",
'overlay_text_encoded': "ote",
'overlay_text_color': "otc",
'overlay_text_width': "otw",
'overlay_text_background': "otbg",
'overlay_text_padding': "otp",
'overlay_text_inner_alignment': "otia",
'overlay_text_transparency': "oa",
'overlay_alpha': "oa",
'overlay_radius': "or",
'overlay_text_typography': "ott",
'overlay_background': "obg",
'progressive': "pr",
'lossless': "lo",
'trim': "t",
Expand All @@ -56,6 +29,8 @@ module SupportedTransformation
'effect_usm': "e-usm",
'effect_contrast': "e-contrast",
'effect_gray': "e-grayscale",
'effect_shadow': "e-shadow",
'effect_gradient': "e-gradient",
'original': "orig",
'raw': 'raw',
}
Expand Down
2 changes: 1 addition & 1 deletion lib/imagekitio/sdk/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module ImageKitIo
module Sdk
VERSION = '2.3.0'
VERSION = '3.0.0'
end
end
25 changes: 25 additions & 0 deletions test/imagekit/api_service/file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,31 @@
expect(@ac[:payload][:fileName]).to eq("fake_name")
expect(upload[:status_code]).to eq(401)
end

it "test_upload_with_valid_expected_success_with_transformation" do
request_obj = double
allow(ImageKitIo::Request)
.to receive(:new)
.with(private_key, public_key, url_endpoint)
.and_return(request_obj)

allow(request_obj)
.to receive(:create_headers)
.and_return({})
@ac={}
allow(request_obj)
.to receive(:request){|method,url,headers,payload| @ac={method: method, url: url, headers: headers, payload:payload}}
.and_return({status_code: 200})

SUT = file_api_service.new(request_obj)

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'}]})

expect(@ac[:payload]['transformation']).to eq("{\"pre\":\"l-text,i-Imagekit,fs-50,l-end\",\"post\":[{\"type\":\"transformation\",\"value\":\"w-100\"}]}")

expect(upload[:status_code]).to eq(200)

end
end

describe 'FileListTest' do
Expand Down
30 changes: 3 additions & 27 deletions test/imagekit/url_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,32 +158,6 @@
rotation: 90,
blur: 10,
named: "some_name",
overlay_x: 35,
overlay_y: 35,
overlay_focus: "bottom",
overlay_height: 20,
overlay_width: 20,
overlay_image: "/folder/file.jpg",
overlay_image_trim: false,
overlay_image_aspect_ratio: "4:3",
overlay_image_background: "0F0F0F",
overlay_image_border: "10_0F0F0F",
overlay_image_DPR: 2,
overlay_image_quality: 50,
overlay_image_cropping: "force",
overlay_text: "two words",
overlay_text_font_size: 20,
overlay_text_font_family: "Open Sans",
overlay_text_color: "00FFFF",
overlay_text_transparency: 5,
overlay_text_typography: "b",
overlay_background: "00AAFF55",
overlay_text_encoded: "b3ZlcmxheSBtYWRlIGVhc3k%3D",
overlay_text_width: 50,
overlay_text_background: "00AAFF55",
overlay_text_padding: 40,
overlay_text_inner_alignment: "left",
overlay_radius: 10,
progressive: true,
lossless: true,
trim: 5,
Expand All @@ -195,12 +169,14 @@
effect_usm: "2-2-0.8-0.024",
effect_contrast: true,
effect_gray: true,
effect_shadow: 'bl-15_st-40_x-10_y-N5',
effect_gradient: 'from-red_to-white',
original: true,
raw: 'w-200,h-200'
},]
}
url = url_obj.generate_url(options)
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")
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")
end

it "test_generate_url_with_chained_transformation" do
Expand Down

0 comments on commit 57610a7

Please sign in to comment.