Fixes #3169 - Logo image ratio goes wrong when resizing to specific height

This commit is contained in:
Mantas 2019-06-06 16:28:35 +03:00 committed by Mantas Masalskis
parent 52a44abc2d
commit 08f840b1dc
5 changed files with 35 additions and 2 deletions

View file

@ -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')

View file

@ -0,0 +1,15 @@
<link rel="stylesheet" href="/assets/tests/qunit-1.21.0.css">
<%= javascript_include_tag "/assets/tests/qunit-1.21.0.js", "/assets/tests/image_service.js", nonce: true %>
<style type="text/css">
body {
padding-top: 0px;
}
</style>
<script type="text/javascript">
</script>
<div id="qunit" class="u-dontfold"></div>

View file

@ -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

View file

@ -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/dgAAA6ppVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDUuNC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd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EQVRIDe3SsQ0AIAwDQWD/nYNo3X9S8Onc2NIpu6rWxJ2J0bfpcJu81FJjAj4XRpvFUqcIlqXGaLNY6hTBstQYbRZLnSJY/o/6AhOiAzl4JlrsAAAAAElFTkSuQmCC'

View file

@ -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