Skip to content

Commit

Permalink
resize with aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
viliusle committed May 10, 2018
1 parent f736445 commit 6b7d100
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/js/modules/image/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 21 additions & 5 deletions src/js/modules/image/size.js
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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) {
Expand All @@ -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");
Expand Down

0 comments on commit 6b7d100

Please sign in to comment.