From 08f840b1dc3703de4f70a39e9300d921d5d3a3ec Mon Sep 17 00:00:00 2001 From: Mantas Date: Thu, 6 Jun 2019 16:28:35 +0300 Subject: [PATCH] Fixes #3169 - Logo image ratio goes wrong when resizing to specific height --- .../app/lib/app_post/image_service.coffee | 4 ++-- app/views/tests/image_service.html.erb | 15 +++++++++++++++ config/routes/test.rb | 1 + public/assets/tests/image_service.js | 13 +++++++++++++ spec/system/js/q_unit_spec.rb | 4 ++++ 5 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 app/views/tests/image_service.html.erb create mode 100644 public/assets/tests/image_service.js diff --git a/app/assets/javascripts/app/lib/app_post/image_service.coffee b/app/assets/javascripts/app/lib/app_post/image_service.coffee index c68ed442d..8c94b182d 100644 --- a/app/assets/javascripts/app/lib/app_post/image_service.coffee +++ b/app/assets/javascripts/app/lib/app_post/image_service.coffee @@ -39,8 +39,8 @@ class App.ImageService y = imageHeight / factor if x is 'auto'# && (y * factor) >= imageWidth - factor = imageWidth / y - x = imageHeight / factor + factor = imageHeight / y + x = imageWidth / factor canvas = document.createElement('canvas') diff --git a/app/views/tests/image_service.html.erb b/app/views/tests/image_service.html.erb new file mode 100644 index 000000000..555e4f0c6 --- /dev/null +++ b/app/views/tests/image_service.html.erb @@ -0,0 +1,15 @@ + + +<%= javascript_include_tag "/assets/tests/qunit-1.21.0.js", "/assets/tests/image_service.js", nonce: true %> + + + + + +
+ diff --git a/config/routes/test.rb b/config/routes/test.rb index cc45d1b7d..69f380570 100644 --- a/config/routes/test.rb +++ b/config/routes/test.rb @@ -29,6 +29,7 @@ Zammad::Application.routes.draw do match '/tests_ticket_macro', to: 'tests#ticket_macro', via: :get match '/tests_ticket_selector', to: 'tests#ticket_selector', via: :get match '/tests_taskbar', to: 'tests#taskbar', via: :get + match '/tests_image_service', to: 'tests#image_service', via: :get match '/tests_text_module', to: 'tests#text_module', via: :get match '/tests_color_object', to: 'tests#color_object', via: :get match '/tests_kb_video_embeding', to: 'tests#kb_video_embeding', via: :get diff --git a/public/assets/tests/image_service.js b/public/assets/tests/image_service.js new file mode 100644 index 000000000..83df8bfff --- /dev/null +++ b/public/assets/tests/image_service.js @@ -0,0 +1,13 @@ +// image service +test('test image resizing with defined height', function(assert) { + var async_done = assert.async(1) + + App.ImageService.resize(image_40x30, 'auto', 15, 1, 'image/png', 0.7, function(image, width, height) { + equal(width, 20) + + async_done() + }) + +}); + +var image_40x30 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAeCAIAAADRv8uKAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAuIwAALiMBeKU/dgAAA6ppVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIgogICAgICAgICAgICB4bWxuczp0aWZmPSJodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyIKICAgICAgICAgICAgeG1sbnM6ZXhpZj0iaHR0cDovL25zLmFkb2JlLmNvbS9leGlmLzEuMC8iPgogICAgICAgICA8eG1wOk1vZGlmeURhdGU+MjAxOS0wNy0wOVQxMzowNzo5ODwveG1wOk1vZGlmeURhdGU+CiAgICAgICAgIDx4bXA6Q3JlYXRvclRvb2w+UGl4ZWxtYXRvciAzLjguNTwveG1wOkNyZWF0b3JUb29sPgogICAgICAgICA8dGlmZjpPcmllbnRhdGlvbj4xPC90aWZmOk9yaWVudGF0aW9uPgogICAgICAgICA8dGlmZjpDb21wcmVzc2lvbj4wPC90aWZmOkNvbXByZXNzaW9uPgogICAgICAgICA8dGlmZjpSZXNvbHV0aW9uVW5pdD4yPC90aWZmOlJlc29sdXRpb25Vbml0PgogICAgICAgICA8dGlmZjpZUmVzb2x1dGlvbj4zMDA8L3RpZmY6WVJlc29sdXRpb24+CiAgICAgICAgIDx0aWZmOlhSZXNvbHV0aW9uPjMwMDwvdGlmZjpYUmVzb2x1dGlvbj4KICAgICAgICAgPGV4aWY6UGl4ZWxYRGltZW5zaW9uPjQwPC9leGlmOlBpeGVsWERpbWVuc2lvbj4KICAgICAgICAgPGV4aWY6Q29sb3JTcGFjZT4xPC9leGlmOkNvbG9yU3BhY2U+CiAgICAgICAgIDxleGlmOlBpeGVsWURpbWVuc2lvbj4zMDwvZXhpZjpQaXhlbFlEaW1lbnNpb24+CiAgICAgIDwvcmRmOkRlc2NyaXB0aW9uPgogICA8L3JkZjpSREY+CjwveDp4bXBtZXRhPgqEC5leAAAAS0lEQVRIDe3SsQ0AIAwDQWD/nYNo3X9S8Onc2NIpu6rWxJ2J0bfpcJu81FJjAj4XRpvFUqcIlqXGaLNY6hTBstQYbRZLnSJY/o/6AhOiAzl4JlrsAAAAAElFTkSuQmCC' diff --git a/spec/system/js/q_unit_spec.rb b/spec/system/js/q_unit_spec.rb index 94d05234d..0f675c183 100644 --- a/spec/system/js/q_unit_spec.rb +++ b/spec/system/js/q_unit_spec.rb @@ -62,6 +62,10 @@ RSpec.describe 'QUnit', type: :system, authenticated_as: false, set_up: true, we it 'Ticket selector' do q_unit_tests('ticket_selector') end + + it 'Image Service' do + q_unit_tests('image_service') + end end context 'Form' do