diff --git a/.github/workflows/gempush.yml b/.github/workflows/gempush.yml index e6acf51..cfdff3a 100644 --- a/.github/workflows/gempush.yml +++ b/.github/workflows/gempush.yml @@ -14,10 +14,10 @@ jobs: uses: ruby/setup-ruby@v1.126.0 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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6d942a0..8c68db1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,9 +13,10 @@ jobs: uses: ruby/setup-ruby@v1.126.0 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 diff --git a/README.md b/README.md index 62976b0..f6b72bf 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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-on-rails) 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: @@ -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. @@ -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 | @@ -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` | diff --git a/lib/active_storage/service/ik_file.rb b/lib/active_storage/service/ik_file.rb index f855b5d..9b2b8f0 100644 --- a/lib/active_storage/service/ik_file.rb +++ b/lib/active_storage/service/ik_file.rb @@ -106,6 +106,10 @@ def updated_at def extension_status identifier['extensionStatus'] end + + def transformation + identifier['transformation'] + end end end end diff --git a/lib/imagekitio/api_service/file.rb b/lib/imagekitio/api_service/file.rb index f59d328..986cd21 100644 --- a/lib/imagekitio/api_service/file.rb +++ b/lib/imagekitio/api_service/file.rb @@ -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" diff --git a/lib/imagekitio/constants/file.rb b/lib/imagekitio/constants/file.rb index bea30fa..498e0d9 100644 --- a/lib/imagekitio/constants/file.rb +++ b/lib/imagekitio/constants/file.rb @@ -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 diff --git a/lib/imagekitio/constants/supported_transformation.rb b/lib/imagekitio/constants/supported_transformation.rb index 06b3d1b..c8158b6 100644 --- a/lib/imagekitio/constants/supported_transformation.rb +++ b/lib/imagekitio/constants/supported_transformation.rb @@ -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", @@ -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', } diff --git a/lib/imagekitio/sdk/version.rb b/lib/imagekitio/sdk/version.rb index b409a95..c188581 100644 --- a/lib/imagekitio/sdk/version.rb +++ b/lib/imagekitio/sdk/version.rb @@ -1,5 +1,5 @@ module ImageKitIo module Sdk - VERSION = '2.3.0' + VERSION = '3.0.0' end end diff --git a/test/imagekit/api_service/file_test.rb b/test/imagekit/api_service/file_test.rb index 563ac73..a2aa8cf 100644 --- a/test/imagekit/api_service/file_test.rb +++ b/test/imagekit/api_service/file_test.rb @@ -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 diff --git a/test/imagekit/url_test.rb b/test/imagekit/url_test.rb index 358351f..88b6051 100644 --- a/test/imagekit/url_test.rb +++ b/test/imagekit/url_test.rb @@ -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, @@ -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