-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
150 lines (126 loc) · 3.73 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
const {remote} = require('electron');
var app = angular.module('app', ['ngRoute']);
app.service('image', function() {
var imagePath = "";
var dimesions = [];
this.setImagePath = function(path) {
imagePath = path;
};
this.getImagePath = function() {
return imagePath;
};
this.setImageDimensions = function(imgDimesions) {
dimesions = imgDimesions;
};
this.getImageDimensions = function() {
return dimesions;
};
});
app.config(function($routeProvider){
$routeProvider
.when('/',{
templateUrl : `${__dirname}/components/home/home.html`,
controller: 'homeCtrl'
})
.when('/edit',{
templateUrl : `${__dirname}/components/editImage/editImage.html`,
controller: 'editCtrl'
})
.otherwise({
templateUrl : '404 bro'
})
});
app.controller('headCtrl', function($scope){
var win = remote.getCurrentWindow();
$scope.close = function(){
win.close();
}
$scope.maximize = function(){
win.isMaximized() ? win.unmaximize() : win.maximize();
}
$scope.minimize = function(){
win.minimize();
}
});
app.controller('homeCtrl', function($scope, $location , image) {
$scope.pickFile = function() {
var {dialog} = remote;
dialog.showOpenDialog({
properties: ['openFile'],
filters: [{
name: 'Images',
extensions: ['jpg', 'jpeg', 'png']
}]
}, function(file) {
if(!!file) {
var path = file[0];
image.setImagePath(path);
var sizeof = require('image-size');
var dimesions = sizeof(path); // dimesions.width and dimesions.height
image.setImageDimensions(dimesions);
$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) { // i = Brightness and $scope.effects[i].val
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(){
//the magic goes
const {BrowserWindow} = remote;
var dimesions = image.getImageDimensions();
let src = image.getImagePath();
let styles = imageReference.style.filter;
let win = new BrowserWindow({
frame: false,
show: false,
width: dimesions.width,
height: dimesions.height,
webPreferences: {
nodeIntegration: true,
webSecurity: false
}
});
win.loadURL(`data:text/html,
<style>*{margin:0;padding:0;}</style><img src="${src}" style="filter: ${styles}">
<script>
var screenshot = require('electron-screenshot');
screenshot({
filename: 'userFile.png',
delay: 1000
});
</script>
`);
}
});