create account

Image Editor Application With Electron(Part-1) by pckurdu

View this thread on: hive.blogpeakd.comecency.com
· @pckurdu ·
$29.49
Image Editor Application With Electron(Part-1)
![Untitled-2.fw.png](https://cdn.steemitimages.com/DQmexrE35uk8rQeynXZ1T4aGcG4EbBnjiarHGwe3u9DMRQ8/Untitled-2.fw.png)

# Repository

### Electron GitHub Address
https://github.com/electron/electron

### My GitHub Address
https://github.com/pckurdu

### This Project GitHub Addres
https://github.com/pckurdu/Image-Editor-Application-Part-1

# What Will I Learn?

- You will learn to create an application with electron.
- You will learn to create custom frames for your electron applications.
- You will learn to work angular codes in electron.
- You will learn the `getCurrentWindow()` function in electron.
- You will learn the functions `close()`, `maximize()`, `unmaximize()`, and `minimize()` in electron.
- You will learn `display: flex` in css.
- You will learn the `transition` feature in css.

# Requirements

- basic electronjs knowledge
- basic css knowledge
- basic angularjs knowledge
- <a href="https://atom.io/">Atom Editor</a>

# Difficulty
- Basic

# Tutorial Contents

In this tutorial series, I will show you how to do image editing with electron. I'll start practicing an electron application from scratch and will teach you how to make each step step by step.

Throughout this application:

- How to create an electron application.
- How to customize the toolbar area of the application.
- How to use dialog windows with electron.
- How to use angularjs in electron applications.

You will learn the answers to the main questions such as.

In this tutorial we will create electron application and we will design the toolbar area of this application and make it functional for this area we designed.

Let's start

### Create Basic Electron Application 

First create a `package.json` file using npm. We need to write the `npm init` command at the command line to create this file.
![electron1.JPG](https://cdn.steemitimages.com/DQmWEkFeqSAZfnho8gPVzRCQ2xJqY2Mf26yLQMuLxCL69cY/electron1.JPG)
<br>
To create an electron application we need to create the file we wrote for the `main` property.

Let's create a `main.js` file at the same place as the `package.json` file.

We need two basic modules to create an electron application.

With the `app` module we can create the electron application and make the application settings.

With the `BrowserWindow` module, we can create the window of the electron application and make the necessary window settings.
```
//load modules
const {app,BrowserWindow}=require('electron')
```
<br>
We must create a function from which we set the window settings after loading these modules.

We can set the size of the window in this function and we can define the page to be displayed in the window.
```
const path=require('path')
const url=require('url')

let win 

function crtWindow(){
    win=new BrowserWindow({width:800,height:600})

    win.loadURL(url.format({
        pathname:path.join(__dirname,'index.html'),
        protocol:'file',
        slashes:true

    }))

    win.openDevTools()
}
```
<br>
With the `BrowserWindow()` function, we can make window settings.

With the `loadURL()` function we can define the page to be loaded.

Open the chrome developer tool with the `openDevTools()` function.

We can run this function with the `ready` command. To do this we use the `app` module.
```
app.on('ready',crtWindow)
```
<br>
Then create the `index.html` page.
```
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Image Editor Application</title>
</head>
<body>
    <h1>Hello pckurdu</h1>
</body>
</html>
```
<br>
Thus, we created the basic electron application.
![electron2.JPG](https://cdn.steemitimages.com/DQmP5DkvmYPYchfgayQnhH6uCU3WGm8QoaFiu5X6X2W9obf/electron2.JPG)
<br>
### Create New Frame
I plan to do application more simply. The frame area in the electron window creates image pollution for this application.

We must destroy the default frame field in order to create this frame field myself.

We need to set the `frame` property to false in the `BrowserWindow()` function.
```
win=new BrowserWindow({width:800,height:600,frame:false})
```
<br>
![electron3.JPG](https://cdn.steemitimages.com/DQma13WqjU27HpFWGsxM7eoxqmFJV3n2BumVReDGhMtwY63/electron3.JPG)
<br>
We removed the frame field, but at this time we can not perform window operations. For example; we can not close the window or we can not bring it to the icon state.

I will use the angularjs library to interact with the application.

I will load `angular CDN` and `angular-route CDN` to the page so I will write my angular code into the `script.js` file.

In index.html
```
<script src="https://code.angularjs.org/1.6.4/angular.min.js"></script>
<script src="https://code.angularjs.org/1.6.4/angular-route.min.js"></script>
<script src="script.js"></script
```
<br>
What I want to do is to close the application, make the window full screen and bring the application to the icon, so I need to create the frame area and place the buttons in this area.

I'll use the `fontawesome` library because I want to shape the buttons according to what they do.

I load the fontawesome library on the `index.html`.
```
<link rel="stylesheet" href=https://use.fontawesome.com/releases/v5.2.0/css/all.css integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
```
<br>
I can now create buttons.
```
<body>
    <div id="window">
        <div id="frame">
            <div id="close"><i class="far fa-window-close"></i></div>
            <div id="max"  ><i class="far fa-window-maximize"></i></div>
            <div id="min"  ><i class="far fa-window-minimize"></i></div>
        </div>
    </div>
</body>
```
<br>
So we get the picture below.
![electron4.JPG](https://cdn.steemitimages.com/DQmNM3nikSGxuMmuDAkKxmBiVJEvWgpXJ2LTcus6M1Ct5CW/electron4.JPG)
<br>
We only get images of these buttons. I will use the angular library to add functionality to the buttons.

### Add Functionality to Buttons

Let's open the `script.js` file and define the angular.
```
var app=angular.module('myApp',['ngRoute']);
```
<br>
I have defined the app module with `angular.module`.

I have already defined it for future use in the `ngRoute` module. I will use the ngRoute module for routing operations.

I have to use the `getCurrentWindow()` method in the `renderer process` to access the properties of the window.

Since the `getCurrentWindow()` function is contained in the `remote` module, we need define the remote model.
```
const {remote}=require('electron')
```
<br>
I create a controller to control the frame area. I will define the getCurrentWindow() function in this controller.
```
app.controller('frameCtrl',function($scope){

    var win=remote.getCurrentWindow();

});
```
<br>
I will define the close function to close the window.
```
$scope.close=function(){
    win.close();
}
```
<br>
The application will close when the `win.close()` method is executed.

I will define the min function to bring the application into symbolic form.
```
$scope.min=function(){
   win.minimize();
}
```
<br>
I will create max function to make the application full screen.
```
$scope.max=function(){
        if(win.isMaximized()){
            win.unmaximize()
        }else{
            win.maximize()
        }
}
```
<br>
We should first check the size of the window.

If it is the screen size, we have to bring it to the previous position or we must bring the window to full screen size if it is normal size.

We can now add buttons functionality to the `index.html` page using the `ng-click` method.

We need to specify the controller's domain using the `ng-app` and `ng-controller` methods.
```
<body ng-app="myApp">
    <div id="window">
        <div id="frame" ng-controller="frameCtrl">
            <div id="close" ng-click="close()"><i class="far fa-window-close"></i></div>
            <div id="max" ng-click="max()"><i class="far fa-window-maximize"></i></div>
            <div id="min" ng-click="min()" ><i class="far fa-window-minimize"></i></div>
        </div>
    </div>
</body>
```
<br>
![ezgif1.gif](https://cdn.steemitimages.com/DQmP5MAjcE4Ji8NXJwi3fhA4ytVNm4uzdKYvjaKrMmMsEKq/ezgif1.gif)
<br>
### Add Style The Frame Field

We do not like to keep our frame area like this.

Let's create a `style.css` file and give it a style for this field.

First let's set the page's edges and gaps.
```
*{
    margin:0;
    padding:0;
    box-sizing: border-box;
}
```
<br>
We can start to give style to the `frame` class.

With `display: flex` we can position the buttons horizontally.

`justified content: flexible start;` We can sort the objects from the beginning.

With `background-color` we can give the element background color using the frame class.

We can adjust height with `height`.
```
#frame{
    
    display: flex;/*horizontal position*/
    justify-content: flex-start;
    background-color: #fdcb6e;
    height: 40px;

}
```
<br>
The new appearance of the application is as follows.
![electron5.JPG](https://cdn.steemitimages.com/DQmeRPhWuH9DbmLGawgK2y5jQRcHREeXbh7dWyBsEbCjsTx/electron5.JPG)
<br>
When it comes to the pointer with the `hover`, we can give the elements other styles.
```
#max:hover{
    background-color: #ffeaa7;
    color:#d63031;
}
#min:hover{
    background-color: #ffeaa7;
    color:#d63031;
}

#close:hover{
    background-color: #d63031;
    color:#ffeaa7;
}
```
<br>
So we can now see the different styles when it comes to pointers on buttons.
![ezgif2.gif](https://cdn.steemitimages.com/DQmZ1wXFSmvsKLTEugVgqyAPcXANPUhLSkKDwPjFPyPTZx8/ezgif2.gif)
<br>
I want to push a little bit from the boxes inside the buttons so I will center it on the inside also I will size the box.
```
.far{
    padding: 3px 5px 5px 5px;
    font-size: 25px;
    cursor: pointer;
    
}
```
<br>
Let's use this `far` class for all the buttons.
```
<div class="far" id="close" ng-click="close()"><i class="far fa-window-close"></i></div>
<div class="far" id="max" ng-click="max()"><i class="far fa-window-maximize"></i></div>
<div class="far" id="min" ng-click="min()"><i class="far fa-window-minimize"></i></div>
```
<br>
Finally, let's animate this frame field.

Apply a transition to frame id. We must provide a property to apply transitions. We can switch according to this feature.

Then start this frame field from the top of the screen with the `margin-top` property.

Set the transition property to `margin` and terminate the process in `2` seconds.
```
#frame{
    
    display: flex;/*horizontal position*/
    justify-content: flex-start;
    background-color: #fdcb6e;
    height: 40px;
    transition: margin 2s;
    margin-top: -30px;

}
```
<br>
We set the starting point to `-30px` because the height of our frame field is `40 px` so the `10px` area will appear.

Let's make the height again by `40px` when it comes to pointer with this `10px` area.
```
#frame:hover {
    height: 40px;
    margin-top: 0px;
}
```
<br>
So we have completed the frame area of our application.
![ezgif3.gif](https://cdn.steemitimages.com/DQmWjsk3LmgLN6BTZ3avp7mnQ38MT9EgS7fnGoQCDFz2VQA/ezgif3.gif)
<br>

# Proof of Work Done

https://github.com/pckurdu/Image-Editor-Application-Part-1
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorpckurdu
permlinkimage-editor-application-with-electron-part-1
categoryutopian-io
json_metadata{"tags":["utopian-io","tutorials","electron","angularjs","application-construction"],"image":["https://cdn.steemitimages.com/DQmexrE35uk8rQeynXZ1T4aGcG4EbBnjiarHGwe3u9DMRQ8/Untitled-2.fw.png","https://cdn.steemitimages.com/DQmWEkFeqSAZfnho8gPVzRCQ2xJqY2Mf26yLQMuLxCL69cY/electron1.JPG","https://cdn.steemitimages.com/DQmP5DkvmYPYchfgayQnhH6uCU3WGm8QoaFiu5X6X2W9obf/electron2.JPG","https://cdn.steemitimages.com/DQma13WqjU27HpFWGsxM7eoxqmFJV3n2BumVReDGhMtwY63/electron3.JPG","https://cdn.steemitimages.com/DQmNM3nikSGxuMmuDAkKxmBiVJEvWgpXJ2LTcus6M1Ct5CW/electron4.JPG","https://cdn.steemitimages.com/DQmP5MAjcE4Ji8NXJwi3fhA4ytVNm4uzdKYvjaKrMmMsEKq/ezgif1.gif","https://cdn.steemitimages.com/DQmeRPhWuH9DbmLGawgK2y5jQRcHREeXbh7dWyBsEbCjsTx/electron5.JPG","https://cdn.steemitimages.com/DQmZ1wXFSmvsKLTEugVgqyAPcXANPUhLSkKDwPjFPyPTZx8/ezgif2.gif","https://cdn.steemitimages.com/DQmWjsk3LmgLN6BTZ3avp7mnQ38MT9EgS7fnGoQCDFz2VQA/ezgif3.gif"],"links":["https://github.com/electron/electron","https://github.com/pckurdu","https://github.com/pckurdu/Image-Editor-Application-Part-1","https://atom.io/"],"app":"steemit/0.1","format":"markdown"}
created2018-09-06 11:01:09
last_update2018-09-06 11:01:09
depth0
children4
last_payout2018-09-13 11:01:09
cashout_time1969-12-31 23:59:59
total_payout_value22.435 HBD
curator_payout_value7.054 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length11,226
author_reputation23,385,816,696,918
root_title"Image Editor Application With Electron(Part-1)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id70,491,917
net_rshares27,713,977,373,524
author_curate_reward""
vote details (27)
@portugalcoin ·
$8.39
Thank you for your contribution.

The features you present in your tutorial are simple, but the tutorial is very well explained.

Thanks for your work and hope to see more of your tutorials.

Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/8/11321313).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , ,
properties (23)
authorportugalcoin
permlinkre-pckurdu-image-editor-application-with-electron-part-1-20180907t202114052z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"links":["https://join.utopian.io/guidelines","https://review.utopian.io/result/8/11321313","https://support.utopian.io/","https://discord.gg/uTyJkNm","https://join.utopian.io/"],"app":"steemit/0.1"}
created2018-09-07 20:21:15
last_update2018-09-07 20:21:15
depth1
children1
last_payout2018-09-14 20:21:15
cashout_time1969-12-31 23:59:59
total_payout_value6.334 HBD
curator_payout_value2.051 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length682
author_reputation599,460,589,822,571
root_title"Image Editor Application With Electron(Part-1)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id70,639,951
net_rshares8,101,364,016,602
author_curate_reward""
vote details (9)
@utopian-io ·
Thank you for your review, @portugalcoin!

So far this week you've reviewed 3 contributions. Keep up the good work!
properties (22)
authorutopian-io
permlinkre-re-pckurdu-image-editor-application-with-electron-part-1-20180907t202114052z-20180913t083512z
categoryutopian-io
json_metadata"{"app": "beem/0.19.42"}"
created2018-09-13 08:35:15
last_update2018-09-13 08:35:15
depth2
children0
last_payout2018-09-20 08:35:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length115
author_reputation152,955,367,999,756
root_title"Image Editor Application With Electron(Part-1)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id71,157,842
net_rshares0
@steem-ua ·
#### Hi @pckurdu!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
authorsteem-ua
permlinkre-image-editor-application-with-electron-part-1-20180907t212826z
categoryutopian-io
json_metadata"{"app": "beem/0.19.54"}"
created2018-09-07 21:28:27
last_update2018-09-07 21:28:27
depth1
children0
last_payout2018-09-14 21:28:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length286
author_reputation23,214,230,978,060
root_title"Image Editor Application With Electron(Part-1)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id70,643,856
net_rshares0
@utopian-io ·
Hey, @pckurdu!

**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Get higher incentives and support Utopian.io!**
 Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via [SteemPlus](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
authorutopian-io
permlinkre-image-editor-application-with-electron-part-1-20180908t224136z
categoryutopian-io
json_metadata"{"app": "beem/0.19.42"}"
created2018-09-08 22:41:36
last_update2018-09-08 22:41:36
depth1
children0
last_payout2018-09-15 22:41:36
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length589
author_reputation152,955,367,999,756
root_title"Image Editor Application With Electron(Part-1)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id70,737,489
net_rshares0