diff --git a/package-lock.json b/package-lock.json index 4b045739..225e777a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4428,7 +4428,7 @@ } }, "hermite-resize": { - "version": "git+https://github.com/viliusle/Hermite-resize.git#75fd0e77179ae0b5296488722eb114d18becca5f" + "version": "git+https://github.com/viliusle/Hermite-resize.git#d88a9ee6df9555a4a9a5892ae570548a8384237f" }, "hmac-drbg": { "version": "1.0.1", diff --git a/src/js/modules/image/resize.js b/src/js/modules/image/resize.js index cbce64c3..1dc99d09 100644 --- a/src/js/modules/image/resize.js +++ b/src/js/modules/image/resize.js @@ -3,7 +3,7 @@ import Base_layers_class from './../../core/base-layers.js'; import Base_gui_class from './../../core/base-gui.js'; import Dialog_class from './../../libs/popup.js'; import ImageFilters_class from './../../libs/imagefilters.js'; -import Hermite_class from './../../../../node_modules/hermite-resize/dist/hermite.npm.js'; +import Hermite_class from 'hermite-resize'; import alertify from './../../../../node_modules/alertifyjs/build/alertify.min.js'; var instance = null; diff --git a/src/js/modules/image/size.js b/src/js/modules/image/size.js index 67546099..a5f46254 100644 --- a/src/js/modules/image/size.js +++ b/src/js/modules/image/size.js @@ -1,6 +1,7 @@ import config from './../../config.js'; import Base_gui_class from './../../core/base-gui.js'; import Dialog_class from './../../libs/popup.js'; +import alertify from './../../../../node_modules/alertifyjs/build/alertify.min.js'; class Image_size_class { @@ -22,8 +23,8 @@ class Image_size_class { var settings = { title: 'Size', params: [ - {name: "w", title: "Width:", value: config.WIDTH}, - {name: "h", title: "Height:", value: config.HEIGHT}, + {name: "w", title: "Width:", value: config.WIDTH, placeholder: config.WIDTH}, + {name: "h", title: "Height:", value: config.HEIGHT, placeholder: config.HEIGHT}, {name: "resolution", title: "Resolution:", values: resolutions}, ], on_finish: function (params) { @@ -37,12 +38,27 @@ class Image_size_class { size_handler(data) { var width = parseInt(data.w); var height = parseInt(data.h); + var ratio = config.WIDTH / config.HEIGHT; - if (width < 1) + if (width < 1){ width = 1; - if (height < 1) + } + if (height < 1){ height = 1; - + } + + //aspect ratio + if (isNaN(width) && isNaN(height)){ + alertify.error('Wrong dimensions'); + return; + } + if (isNaN(width)){ + width = height * ratio; + } + if (isNaN(height)){ + height = width / ratio; + } + if (data.resolution != 'Custom') { var dim = data.resolution.split(" "); dim = dim[0].split("x");