-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
154 lines (128 loc) · 4.24 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
var app = angular.module('app', ['ngRoute']);
const {remote} = require('electron');
app.service('image', function(){
var imagePath = "";
var imageDimensions = [];
this.setImagePath = function(path) {
imagePath = path;
}
this.getImagePath = function() {
return imagePath;
}
this.setImageDimensions = function(dimensions){
imageDimensions = dimensions;
}
this.getImageDimensions = function(dimensions){
return imageDimensions;
}
});
app.config(function($routeProvider){
$routeProvider.when('/', {
templateUrl: `${__dirname}/components/home/home.html`,
controller: 'homeCtrl'
}).when('/edit',{
templateUrl: `${__dirname}/components/edit/edit.html`,
controller: 'editCtrl'
}).otherwise({
template: `404 NOT FOUND`
});
});
app.controller('headCtrl', function($scope) {
var window = remote.BrowserWindow.getFocusedWindow();
$scope.close = function() {
window.close();
};
$scope.minimize = function() {
window.minimize();
};
$scope.maximize = function() {
window.isMaximized() ? window.unmaximize() : window.maximize();
};
});
app.controller('homeCtrl', function($scope, $location, image) {
$scope.pickFile = function () {
var {dialog} = remote;
dialog.showOpenDialog({
properties: ['openFile'],
filters: [
{name: 'Images', extensions: ['jpg', 'jpeg', 'png', 'gif']},
]
}, function(file){
if(!!file) {
var path = file[0];
image.setImagePath(path);
var sizeof = require('image-size');
var dimensions = sizeof(path);
image.setImageDimensions(dimensions);
$location.path('/edit');
$scope.$apply();
}
});
};
});
app.controller('editCtrl', function($scope, image, $location){
$scope.imagePath = image.getImagePath();
$scope.controlsActive = false;
var imageReference = document.getElementById('mainImage');
var generatedStyles = "";
$scope.effects = {
'Brightness': {val: 100, min: 0, max: 200, delim: '%'},
'Contrast': {val: 100, min: 0, max: 200, delim: '%'},
'Invert': {val: 0, min: 0, max: 100, delim: '%'},
'Hue-Rotate': {val: 0, min: 0, max: 360, delim: 'deg'},
'Sepia': {val: 0, min: 0, max: 100, delim: '%'},
'Grayscale': {val: 0, min: 0, max: 100, delim: '%'},
'Saturate': {val: 100, min: 0, max: 200, delim: '%'},
'Blur': {val: 0, min: 0, max: 5, delim: 'px'}
};
$scope.imageEffect = function(effectName) {
$scope.controlsActive = true;
$scope.activeEffect = effectName;
}
$scope.setEffect = function(){
generatedStyles = "";
for(let i in $scope.effects) {
generatedStyles += `${i}(${$scope.effects[i].val + $scope.effects[i].delim}) `;
}
imageReference.style.filter = generatedStyles;
}
$scope.hideThis = function() {
$scope.controlsActive = false;
};
$scope.change = function() {
$location.path('/');
}
$scope.save = function() {
const {BrowserWindow} = remote;
var imageDimensions = image.getImageDimensions();
let src = image.getImagePath();
let style = imageReference.style.filter;
let win = new BrowserWindow({
frame: false,
show: false,
width: imageDimensions.width,
height: imageDimensions.height,
webPreferences: {
webSecurity: false
}
});
win.loadURL(
`data:text/html,
<style>
* {
margin: 0;
padding 0;
}
</style>
<img src="${src}" style="filter: ${style}">
<script>
var screenshot = require('electron-screenshot');
screenshot({
filename: 'untitled.jpg',
delay: 1000
});
</script>
`
);
}
});