Repository: dudewheresmycode/GifTuna Branch: master Commit: a84e275c19c6 Files: 28 Total size: 133.5 KB Directory structure: gitextract__rhz70sy/ ├── .gitignore ├── README.md ├── app/ │ ├── .gitignore │ ├── LICENSE.md │ ├── README.md │ ├── css/ │ │ ├── slider.css │ │ └── style.css │ ├── ffmpeg.html │ ├── index.html │ ├── lib/ │ │ └── minicolors/ │ │ ├── LICENSE.md │ │ ├── README.md │ │ ├── bower.json │ │ ├── component.json │ │ ├── composer.json │ │ ├── gulpfile.js │ │ ├── index.html │ │ ├── jquery.minicolors.css │ │ ├── jquery.minicolors.js │ │ ├── package.json │ │ └── without-bootstrap.html │ ├── main.js │ ├── package.json │ ├── preview.html │ ├── renderer.js │ └── tpl/ │ ├── loader.html │ └── palette.html ├── package.json └── resources/ └── logo-hires-v2.icns ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ node_modules/ app/node_modules .DS_Store build/ ================================================ FILE: README.md ================================================ # GifTuna A gif tuning application for Mac, Windows and Linux. ================================================ FILE: app/.gitignore ================================================ node_modules ================================================ FILE: app/LICENSE.md ================================================ CC0 1.0 Universal ================== Statement of Purpose --------------------- The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work"). Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others. For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights. 1. Copyright and Related Rights. -------------------------------- A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following: i. the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work; ii. moral rights retained by the original author(s) and/or performer(s); iii. publicity and privacy rights pertaining to a person's image or likeness depicted in a Work; iv. rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below; v. rights protecting the extraction, dissemination, use and reuse of data in a Work; vi. database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and vii. other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof. 2. Waiver. ----------- To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose. 3. Public License Fallback. ---------------------------- Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose. 4. Limitations and Disclaimers. -------------------------------- a. No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document. b. Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law. c. Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work. d. Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work. ================================================ FILE: app/README.md ================================================ # electron-quick-start **Clone and run for a quick way to see Electron in action.** This is a minimal Electron application based on the [Quick Start Guide](http://electron.atom.io/docs/tutorial/quick-start) within the Electron documentation. **Use this app along with the [Electron API Demos](http://electron.atom.io/#get-started) app for API code examples to help you get started.** A basic Electron application needs just these files: - `package.json` - Points to the app's main file and lists its details and dependencies. - `main.js` - Starts the app and creates a browser window to render HTML. This is the app's **main process**. - `index.html` - A web page to render. This is the app's **renderer process**. You can learn more about each of these components within the [Quick Start Guide](http://electron.atom.io/docs/tutorial/quick-start). ## To Use To clone and run this repository you'll need [Git](https://git-scm.com) and [Node.js](https://nodejs.org/en/download/) (which comes with [npm](http://npmjs.com)) installed on your computer. From your command line: ```bash # Clone this repository git clone https://github.com/electron/electron-quick-start # Go into the repository cd electron-quick-start # Install dependencies npm install # Run the app npm start ``` Note: If you're using Linux Bash for Windows, [see this guide](https://www.howtogeek.com/261575/how-to-run-graphical-linux-desktop-applications-from-windows-10s-bash-shell/) or use `node` from the command prompt. ## Resources for Learning Electron - [electron.atom.io/docs](http://electron.atom.io/docs) - all of Electron's documentation - [electron.atom.io/community/#boilerplates](http://electron.atom.io/community/#boilerplates) - sample starter apps created by the community - [electron/electron-quick-start](https://github.com/electron/electron-quick-start) - a very basic starter Electron app - [electron/simple-samples](https://github.com/electron/simple-samples) - small applications with ideas for taking them further - [electron/electron-api-demos](https://github.com/electron/electron-api-demos) - an Electron app that teaches you how to use Electron - [hokein/electron-sample-apps](https://github.com/hokein/electron-sample-apps) - small demo apps for the various Electron APIs ## License [CC0 1.0 (Public Domain)](LICENSE.md) ================================================ FILE: app/css/slider.css ================================================ input[type=range] { -webkit-appearance: none; width: 100%; } input[type=range]:disabled { opacity: 0.5; } input[type=range]:focus { outline: none; } input[type=range]::-webkit-slider-runnable-track { width: 90%; height: 10px; cursor: pointer; background: #222; } input[type=range]::-webkit-slider-thumb { width: 18px; height: 18px; background-color: #EE6352; /*background-image:url('../svg/slider.svg');*/ background-repeat: no-repeat; background-size: contain; border-radius: 20px; /*border-top: 10px solid red;*/ /*border-right: 10px solid transparent; border-left: 10px solid transparent; border-bottom: 10px solid #fff;*/ /*border-radius: 28px;*/ /*background: #ffffff;*/ cursor: pointer; -webkit-appearance: none; margin-top: -4px; } input[type=range]:focus::-webkit-slider-runnable-track { background: #333; } ================================================ FILE: app/css/style.css ================================================ body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 13px; background-color: #161516; color: #eee; margin: 0; -webkit-user-select: none; } hr { background: none; border: 0; height: 10px; } a { color: #eee; text-decoration: underline; } a:hover { color: #fff; } a.btn { background-color: #3A393B; padding: 7px 15px; cursor: pointer; text-decoration: none; font-weight: bold; font-size: 14px; } a.disabled, a.btn.disabled { opacity: 0.5; pointer-events: none; cursor: not-allowed; } a.btn.disabled:hover { cursor: not-allowed; } a.btn:hover { background-color: #555; } a.btn:active { background-color: #333; } a.btn.btn-primary { color: #3A393B; background-color: #EE6352; } a.btn.btn-primary:hover { background-color: #F49B90; } a.btn.btn-small { font-size: 12px; padding: 5px 10px; } .app { display: flex; flex-direction: row; height: 100vh; } .app .section { height: 100vh; } .app .section .section-title { border-bottom: 1px solid #444; padding: 7px 0; font-weight: normal; font-size: 12px; color: #aaa; margin: 20px 0 10px 0; /*font-size: 14px; font-weight: normal; border-bottom: 1px solid #444; padding-bottom: 10px;*/ } .app .section .section-title:first-child { margin-top: 10px; } .app .section.settings-form { flex: 0; min-width: 280px; background: #1a1a1a; padding: 0 20px; overflow: auto; box-shadow: 0px 0px 15px rgba(0,0,0,0.45); } .app .section.preview { flex: 1; display: flex; flex-direction: column; overflow: hidden; } .top-header { flex: 0 1 auto; padding: 20px; text-align: right; background: #1a1a1a; display: flex; flex-direction: row; box-shadow: 0px 0px 15px rgba(0,0,0,0.45); /*border-bottom: 1px solid #000;*/ } .top-header .scrubber { flex: 1 1 auto; padding-right: 20px; display: flex; flex-direction: row; } .top-header .scrubber .scrubber-frame { flex: 0 0 auto; min-width: 30px; text-align: center; } .top-header .scrubber .scrubber-bar { flex: 1 1 auto; padding: 0 10px; } .top-header .scrubber input { width: 100%; } .top-header .export { flex: 0 0 auto; min-width: 100px; } .progress-canvas { flex: 1 1 auto; justify-content: center; display: flex; flex-direction: column; } .progress-canvas .progress-canvas-container { width: 80%; text-align: center; padding: 20px; margin: -100px auto 0 auto; /*background: #333;*/ /*box-shadow: 1px 1px 3px rgba(0,0,0,0.35);*/ } .progress-canvas h4 { margin: 20px 0 0 0; padding: 0; } .progress-canvas p { color: #aaa; } .progress-canvas .spinner-icon { display: block; } .progress-canvas .spinner-icon svg { width: 70px; height: 70px; } .preview-canvas { /*height: 100%;*/ flex: 1 1 auto; justify-content: center; align-items: center; display: flex; overflow: auto; /*justify-content: center;*/ /*align-items: center;*/ /*align-content: center;*/ } .preview-img { min-width: 320px; min-height: 240px; width: 100%; height: auto; box-shadow: 1px 0px 5px rgba(0,0,0,0.5); } .preview-canvas .preview-div { display: flex; flex: 1 1 auto; background: #aaa; width: 100%; height: 100%; min-width: 320px; min-height: 240px; background-size: contain; background-repeat: no-repeat; background-position: center center; position: relative; margin: auto; } /* .preview-canvas .preview-wrap { width: 100%; max-width:100%; height:auto; } .preview-canvas .preview-wrap .preview-div { display: block; margin: auto; position: relative; background-size: contain; background-repeat: no-repeat; }*/ .palette-control { /*padding: 10px;*/ width: 100%; /*padding-bottom: 100%;*/ position: relative; margin-top: 15px; /*background: #191919;*/ /*box-shadow: inset 1px 1px 20px #101010;*/ } .palette-control:after { content: ""; display: block; padding-bottom: 100%; } .palette-control .palette { position: absolute; top:0; left: 0; width: 100%; image-rendering: pixelated; } input[type="text"], input[type="number"] { background: #333; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 12px; color: #fff; padding: 5px; border: 0; } input[type="number"] { width: 45px; } input[type="text"]:disabled, input[type="number"]:disabled { opacity: 0.5; cursor: not-allowed; } .custom-select { display: inline-block; position: relative; background: #333; } .custom-select.disabled { opacity: 0.5; cursor: not-allowed; } .custom-select:after { position: absolute; display: block; content: ''; width: 0; height: 0; top:50%; right:7px; margin-top: -2px; border-top: 5px solid #fff; border-left: 5px solid transparent; border-right: 5px solid transparent; pointer-events: none; } .custom-select select { font-size: 12px; outline: none; -webkit-appearance:none; background-color: transparent; min-width: 40px; padding: 5px 25px 5px 5px; border: 0; border-radius: 0; color: #fff; } .custom-range { display: flex; flex-direction: row; } .custom-range .custom-range-value { flex: 0; margin-right: 10px; font-size: 11px; /*min-width: 20px;*/ } .custom-range .custom-range-input { flex: 1; } .form-group { margin: 0; vertical-align: top; } .form-group:last-child { margin: 0; } .form-group.form-group-inline { display: inline-block; margin-right: 20px; } .form-group .form-control { min-height: 30px; line-height: 30px; } .form-group h5 { font-size: 11px; font-weight: normal; color: #aaa; margin: 10px 0; padding: 0; /*text-transform: uppercase;*/ /*letter-spacing: 1px;*/ } h6 { border-bottom: 1px solid #444; padding: 10px 0; font-weight: normal; font-size: 11px; color: #aaa; margin: 0; } ::-webkit-scrollbar { width: 12px; } ::-webkit-scrollbar-track { background: transparent; /*-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);*/ } ::-webkit-scrollbar-thumb { background-color: #323232; border: none; outline: none; /*outline: 1px solid slategrey;*/ border-radius: 20px; } ::-webkit-scrollbar-corner { background-color: transparent; } .input { display: block; } .input .change-it { display: none; } .input:hover .change-it { display: inline-block; color: #aaa; margin-left: 5px; } .install { width: 80%; max-width: 800px; margin: 80px auto; background: #111; padding: 30px; } .install p { font-size: 14px; line-height: 1.5; } .pixel-palette { width: 100%; display: block; position: relative; } .pixel-picker { position: absolute; top: 0; left: 0; display: none; z-index: 999; background: #2a2a2a; padding: 20px; /*margin-top: 36px;*/ /*margin-left: -7px;*/ margin-top: -266px; margin-left: -7px; } .pixel-picker:after { position: absolute; content:''; bottom: -19px; left: 0px; border-top: 20px solid #2a2a2a; border-right: 20px solid transparent; border-left: 20px solid transparent; } .minicolors-panel { height: 152px; } .pixel-picker.open { display: block; } .pixel-picker .hex-control { display: flex; padding: 5px 0; flex-direction: row; } .pixel-picker .hex-control .hex-input-wrapper { flex: 0; } .pixel-picker .hex-control .color-preview { flex: 1; height: 24px; display: block; } .pixel-picker .hex-control input { width: 50px; font-family: monospace; font-size: 12px; text-align: center; } .pixel-picker .picker-actions { padding: 0 0 10px 0px; } .pixel-picker .picker-control { display: block; clear: both; } .pixel-palette .pixel { width: 17.5px; height: 17.5px; float: left; } .pixel-palette .pixel:hover, .pixel-palette .pixel.on { box-shadow: 1px 1px 5px #000; transform: scale(1.5); } .progress { height: 20px; width: 50vw; position: relative; background: #101010; margin: 0 auto; } .progress .progress-fill { height: 20px; background: #46CCF3; position: relative; } .progress .progress-fill.finished { background-color: #57A773; } /* Styles go here */ .progress .progress-fill.spin { /*width: 300px; height: 50px;*/ width: 100% !important; opacity: 0.5; background-image: repeating-linear-gradient(-45deg, #101010, #101010 25px, #46CCF3 25px, #46CCF3 50px); -webkit-animation:progress 1s linear infinite; -moz-animation:progress 1s linear infinite; -ms-animation:progress 1s linear infinite; animation:progress 1s linear infinite; background-size: 150% 100%; } @-webkit-keyframes progress{ 0% { background-position: 0 0; } 100% { background-position: -75px 0px; } } @-moz-keyframes progress{ 0% { background-position: 0 0; } 100% { background-position: -75px 0px; } } @-ms-keyframes progress{ 0% { background-position: 0 0; } 100% { background-position: -75px 0px; } } @keyframes progress{ 0% { background-position: 0 0; } 100% { background-position: -70px 0px; } } .progress-info { display: flex; flex-direction: row; width: 50vw; margin: 0 auto; } .progress-text { padding: 10px 0; margin: 10px 0; font-size: 14px; flex: 1; color: #aaa; } .progress-text.finished { color: #57A773; } .progress-action { padding: 10px 0; margin: 10px 0; flex: 1; text-align: right; } .progress-action a { margin-right: 10px; } .progress-action a.btn { margin-right: 0; } .progress-text-percent { font-weight: bold; display: inline-block; color: #fff; } .progress-text-size { font-size: 11px; margin-left: 5px; display: inline-block; } ================================================ FILE: app/ffmpeg.html ================================================ GifTuna

Download & Install FFmpeg

GifTuna uses ffmpeg under the hood to convert to gif format. Don't fret, we can download this libary for you.

 

Quit Download & Install

Installing ffmpeg...

================================================ FILE: app/index.html ================================================ GifTuna

Input File

Output Options

Dimensions
×
Lock Aspect
FPS

Dither Options

Dither
Dither Grid
Palette Mode
Stats Mode

Color Palette

Colors
{{status.export.progress|number:1}}% Complete Canceling {{status.export.size|filesize}} written

Scanning Input

Generating Color Palette

This could take a while for longer gifs...


Cancel

Generating Preview

================================================ FILE: app/lib/minicolors/LICENSE.md ================================================ Copyright 2017 A Beautiful Site, LLC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: app/lib/minicolors/README.md ================================================ # jQuery MiniColors: A tiny color picker built on jQuery Developed by Cory LaViska for A Beautiful Site, LLC Licensed under the MIT license: http://opensource.org/licenses/MIT ## Demo & Documentation http://labs.abeautifulsite.net/jquery-minicolors/ ## Install via NPM This is the official NPM version of MiniColors: ``` npm install --save @claviska/jquery-minicolors ``` **Note:** There is another version on NPM without the namespace that is out of date and not supported. I did not create it nor do I have control of it. Please use the official NPM version to ensure you have the latest updates. ================================================ FILE: app/lib/minicolors/bower.json ================================================ { "name": "jquery-minicolors", "version": "2.2.6", "homepage": "https://github.com/claviska/jquery-minicolors", "authors": [ "Cory LaViska" ], "description": "jQuery MiniColors Plugin", "main": [ "./jquery.minicolors.js", "./jquery.minicolors.css" ], "keywords": [ "jquery", "colorpicker" ], "license": "MIT", "ignore": [ "**/.*", "node_modules", "bower_components", "test", "tests" ] } ================================================ FILE: app/lib/minicolors/component.json ================================================ { "name": "jquery-minicolors", "version": "2.2.6", "description": "jQuery MiniColors Plugin", "homepage": "", "main": [ "./jquery.minicolors.js", "./jquery.minicolors.css" ], "dependencies": { "jquery": ">= 1.7.x" }, "keywords": [ "jquery", "colorpicker" ], "author": { "name": "Cory LaViska", "web": "http://www.abeautifulsite.net/" }, "license": [ "http://www.opensource.org/licenses/mit-license.php" ] } ================================================ FILE: app/lib/minicolors/composer.json ================================================ { "name": "abeautifulsite/jquery-minicolors", "type": "component", "description": "jQuery MiniColors Plugin", "homepage": "http://www.abeautifulsite.net/", "license": "MIT", "extra": { "component": { "scripts": [ "jquery.minicolors.js" ], "files": [ "jquery.minicolors.js", "jquery.minicolors.min.js", "jquery.minicolors.css", "jquery.minicolors.png" ] } } } ================================================ FILE: app/lib/minicolors/gulpfile.js ================================================ /* eslint-env node, es6 */ 'use strict'; const gulp = require('gulp-help')(require('gulp')); const del = require('del'); const rename = require('gulp-rename'); const uglify = require('gulp-uglify'); // Clean gulp.task('clean', 'Clean up!', () => { return del('jquery.minicolors.min.js'); }); // Minify gulp.task('minify', 'Minify it!', ['clean'], () => { return gulp.src('jquery.minicolors.js') .pipe(uglify({ preserveComments: 'license' })) .on('error', (err) => { console.error(err); this.emit('end'); }) .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest(__dirname)); }); // Watch for changes gulp.task('watch', 'Watch for changes!', () => { gulp.watch('jquery.minicolors.js', ['minify']); }); // Default gulp.task('default', 'The default task.', ['watch']); ================================================ FILE: app/lib/minicolors/index.html ================================================ jQuery MiniColors

jQuery MiniColors

Now with Bootstrap 3 support!

A project by A Beautiful Site, originally developed for Surreal CMS.

Contents

Download

This project is on GitHub. Feel free to post bug reports, feature requests, and code improvements on the official project page.

Download on GitHub

Demos

This is the main demo page, which uses Bootstrap 3, but this plugin works without Bootstrap as well.

View Demo Without Bootstrap

Control Types

Input Modes




Positions

Valid positions include bottom left, bottom right, top left, and top right.

RGB(A)


RGB input can be assigned by setting the format option to rgb.

RGBA input can be assigned by setting the format option to rgb and opacity option to true.

…and more!


Opacity can be assigned by including the data-opacity attribute or by setting the opacity option to true.

CSS-wide keywords can be assigned by setting the keywords option to a comma-separated list of valid keywords: transparent, initial, inherit.

This field has a default value assigned to it, so it will never be empty.

This field will always be uppercase.
Example using Bootstrap's input groups.
Color
Input group example with addon.

Example with swatches.

Example with swatches and opacity.

API

Instantiation

Instantiate like any other jQuery plugin:

$('INPUT.minicolors').minicolors(settings);

Settings

Default settings are as follows:

$.minicolors = {
  defaults: {
    animationSpeed: 50,
    animationEasing: 'swing',
    change: null,
    changeDelay: 0,
    control: 'hue',
    defaultValue: '',
    format: 'hex',
    hide: null,
    hideSpeed: 100,
    inline: false,
    keywords: '',
    letterCase: 'lowercase',
    opacity: false,
    position: 'bottom left',
    show: null,
    showSpeed: 100,
    theme: 'default',
    swatches: []
  }
};

For convenience, you can change default settings globally by assigning new values:

$.minicolors.defaults.changeDelay = 200;

To change multiple properties at once, use $.extend():

$.minicolors.defaults = $.extend($.minicolors.defaults, {
  changeDelay: 200,
  letterCase: 'uppercase',
  theme: 'bootstrap'
});

Note: Changing default settings will not affect controls that are already initialized.

animationSpeed

The animation speed of the sliders when the user taps or clicks a new color. Set to 0 for no animation.

animationEasing

The easing to use when animating the sliders.

changeDelay

The time, in milliseconds, to defer the change event from firing while the user makes a selection. This is useful for preventing the change event from firing frequently as the user drags the color picker around.

The default value is 0 (no delay). If your change callback features something resource-intensive (such as an AJAX request), you’ll probably want to set this to at least 200.

control

Determines the type of control. Valid options are hue, brightness, saturation, and wheel.

defaultValue

To force a default color, set this to a valid hex string. When the user clears the control, it will revert to this color.

format

The format miniColors should use. Valid options are hex and rgb.

hideSpeed & showSpeed

The speed at which to hide and show the color picker.

inline

Set to true to force the color picker to appear inline.

keywords

A comma-separated list of keywords that the control should accept (e.g. inherit, transparent, initial). By default, no keywords are allowed.

letterCase

Determines the letter case of the hex code value. Valid options are uppercase or lowercase.

opacity

Set to true to enable the opacity slider. (Use the input element's data-opacity attribute to set a preset value.)

position

Sets the position of the dropdown. Valid options are bottom left, bottom right, top left, and top right.

The swatchPosition setting has been removed in version 2.1. The position of the swatch is now determined by position.

theme

A string containing the name of the custom theme to be applied. In your CSS, prefix your selectors like this:

.minicolors-theme-yourThemeName { ... }

If you are using the default theme, you will probably need to adjust the swatch styles depending on your existing stylesheet rules. Version 2.1 removes as much styling on the input element as possible, which means it’s up to you to adjust your CSS to make sure the swatch aligns properly.

To adjust the swatch, override these styles:

.minicolors-theme-default .minicolors-swatch {
  top: 5px;
  left: 5px;
  width: 18px;
  height: 18px;
}
.minicolors-theme-default.minicolors-position-right .minicolors-swatch {
  left: auto;
  right: 5px;
}
swatches

An array containing some colors, in either rgb(a) or hex format, that will show up under the main color grid.

Methods

Use this syntax for calling methods:

$(selector).minicolors('method', [data]);
create

Initializes the control for all items matching your selector. This is the default method, so data may be passed in as the only argument.

To set a preset color value, populate the value attribute of the original input element.

destroy

Returns the input element to its original, uninitialized state.

opacity

Gets or sets a control's opacity level. To use this method as a setter, pass data in as a value between 0 and 1. (You can also obtain this value by checking the input element's data-opacity attribute.)

To set a preset opacity value, populate the data-opacity attribute of the original input element.

rgbObject

Returns an object containing red, green, blue, and alpha properties that correspond to the control's current value. Example:

{ r: 0, g: 82, b: 148, a: 0.75 }
rgbString & rgbaString

Returns an RGB or RGBA string suitable for use in your CSS. Examples:

rgb(0, 82, 148)
rgba(0, 82, 148, .75)
settings

Gets or sets a control's settings. If new settings are passed in, the control will destroy and re-initialize itself with any new settings overriding the old ones.

value

Gets or sets a control's color value. To use this method as a setter, pass in a color string or an object (ex: {color: '#fc0', opacity: .5}).

Events

change

Fires when the value of the color picker changes. The this keyword will reference the original input element.

$(selector).minicolors({
  change: function(value, opacity) {
    console.log(value + ' - ' + opacity);
  }
});

Warning! This event will fire a lot when the user drags the color picker around. Use the changeDelay setting to reduce its frequency.

hide

Fires when the color picker is hidden. The this keyword will reference the original input element.

$(selector).minicolors({
  hide: function() {
  console.log('Hide event triggered!');
  }
});
show

Fires when the color picker is shown. The this keyword will reference the original input element.

$(selector).minicolors({
  show: function() {
    console.log('Show event triggered!');
  }
});

License

Licensed under the MIT license, same as jQuery.

©2013 A Beautiful Site, LLC.

================================================ FILE: app/lib/minicolors/jquery.minicolors.css ================================================ .minicolors { position: relative; } .minicolors-sprite { background-image: url(jquery.minicolors.png); } .minicolors-swatch { position: absolute; vertical-align: middle; background-position: -80px 0; border: solid 1px #ccc; cursor: text; padding: 0; margin: 0; display: inline-block; } .minicolors-swatch-color { position: absolute; top: 0; left: 0; right: 0; bottom: 0; } .minicolors input[type=hidden] + .minicolors-swatch { width: 28px; position: static; cursor: pointer; } .minicolors input[type=hidden][disabled] + .minicolors-swatch { cursor: default; } /* Panel */ .minicolors-panel { position: absolute; width: 173px; /*background: white;*/ /*border: solid 1px #CCC;*/ /*box-shadow: 0 0 20px rgba(0, 0, 0, .2);*/ z-index: 99999; box-sizing: content-box; display: none; } .minicolors-panel.minicolors-visible { display: block; } /* Panel positioning */ .minicolors-position-top .minicolors-panel { top: -154px; } .minicolors-position-right .minicolors-panel { right: 0; } .minicolors-position-bottom .minicolors-panel { top: auto; } .minicolors-position-left .minicolors-panel { left: 0; } .minicolors-with-opacity .minicolors-panel { width: 194px; } .minicolors .minicolors-grid { position: relative; top: 1px; left: 1px; width: 150px; height: 150px; background-position: -120px 0; cursor: crosshair; } .minicolors .minicolors-grid-inner { position: absolute; top: 0; left: 0; width: 150px; height: 150px; } .minicolors-slider-saturation .minicolors-grid { background-position: -420px 0; } .minicolors-slider-saturation .minicolors-grid-inner { background-position: -270px 0; background-image: inherit; } .minicolors-slider-brightness .minicolors-grid { background-position: -570px 0; } .minicolors-slider-brightness .minicolors-grid-inner { background-color: black; } .minicolors-slider-wheel .minicolors-grid { background-position: -720px 0; } .minicolors-slider, .minicolors-opacity-slider { position: absolute; top: 1px; left: 152px; width: 20px; height: 150px; /*background-color: white;*/ background-position: 0 0; cursor: row-resize; } .minicolors-slider-saturation .minicolors-slider { background-position: -60px 0; } .minicolors-slider-brightness .minicolors-slider { background-position: -20px 0; } .minicolors-slider-wheel .minicolors-slider { background-position: -20px 0; } .minicolors-opacity-slider { left: 173px; background-position: -40px 0; display: none; } .minicolors-with-opacity .minicolors-opacity-slider { display: block; } /* Pickers */ .minicolors-grid .minicolors-picker { position: absolute; top: 70px; left: 70px; width: 12px; height: 12px; border: solid 1px black; border-radius: 10px; margin-top: -6px; margin-left: -6px; background: none; } .minicolors-grid .minicolors-picker > div { position: absolute; top: 0; left: 0; width: 8px; height: 8px; border-radius: 8px; border: solid 2px white; box-sizing: content-box; } .minicolors-picker { position: absolute; top: 0; left: 0; width: 18px; height: 2px; background: white; border: solid 1px black; margin-top: -2px; box-sizing: content-box; } /* Swatches */ .minicolors-swatches, .minicolors-swatches li { margin: 5px 0 3px 5px; padding: 0; list-style: none; overflow: hidden; } .minicolors-swatches .minicolors-swatch { position: relative; float: left; cursor: pointer; margin:0 4px 0 0; } .minicolors-with-opacity .minicolors-swatches .minicolors-swatch { margin-right: 7px; } .minicolors-swatch.selected { border-color: #000; } /* Inline controls */ .minicolors-inline { display: inline-block; } .minicolors-inline .minicolors-input { display: none !important; } .minicolors-inline .minicolors-panel { position: relative; top: auto; left: auto; box-shadow: none; z-index: auto; display: inline-block; } /* Default theme */ .minicolors-theme-default .minicolors-swatch { top: 5px; left: 5px; width: 18px; height: 18px; } .minicolors-theme-default .minicolors-swatches .minicolors-swatch { margin-bottom: 2px; top: 0; left: 0; width: 18px; height: 18px; } .minicolors-theme-default.minicolors-position-right .minicolors-swatch { left: auto; right: 5px; } .minicolors-theme-default.minicolors { width: auto; display: inline-block; } .minicolors-theme-default .minicolors-input { height: 20px; width: auto; display: inline-block; padding-left: 26px; } .minicolors-theme-default.minicolors-position-right .minicolors-input { padding-right: 26px; padding-left: inherit; } /* Bootstrap theme */ .minicolors-theme-bootstrap .minicolors-swatch { z-index: 2; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 3px; } .minicolors-theme-bootstrap .minicolors-swatches .minicolors-swatch { margin-bottom: 2px; top: 0; left: 0; width: 20px; height: 20px; } .minicolors-theme-bootstrap .minicolors-swatch-color { border-radius: inherit; } .minicolors-theme-bootstrap.minicolors-position-right > .minicolors-swatch { left: auto; right: 3px; } .minicolors-theme-bootstrap .minicolors-input { float: none; padding-left: 44px; } .minicolors-theme-bootstrap.minicolors-position-right .minicolors-input { padding-right: 44px; padding-left: 12px; } .minicolors-theme-bootstrap .minicolors-input.input-lg + .minicolors-swatch { top: 4px; left: 4px; width: 37px; height: 37px; border-radius: 5px; } .minicolors-theme-bootstrap .minicolors-input.input-sm + .minicolors-swatch { width: 24px; height: 24px; } .minicolors-theme-bootstrap .minicolors-input.input-xs + .minicolors-swatch { width: 18px; height: 18px; } .input-group .minicolors-theme-bootstrap:not(:first-child) .minicolors-input { border-top-left-radius: 0; border-bottom-left-radius: 0; } /* Semantic Ui theme */ .minicolors-theme-semanticui .minicolors-swatch { top: 0; left: 0; padding: 18px; } .minicolors-theme-semanticui input { text-indent: 30px; } ================================================ FILE: app/lib/minicolors/jquery.minicolors.js ================================================ // // jQuery MiniColors: A tiny color picker built on jQuery // // Developed by Cory LaViska for A Beautiful Site, LLC // // Licensed under the MIT license: http://opensource.org/licenses/MIT // (function (factory) { if(typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define(['jquery'], factory); } else if(typeof exports === 'object') { // Node/CommonJS module.exports = factory(require('jquery')); } else { // Browser globals factory(jQuery); } }(function ($) { 'use strict'; // Defaults $.minicolors = { defaults: { animationSpeed: 50, animationEasing: 'swing', change: null, changeDelay: 0, control: 'hue', defaultValue: '', format: 'hex', hide: null, hideSpeed: 100, inline: false, keywords: '', letterCase: 'lowercase', opacity: false, position: 'bottom left', show: null, showSpeed: 100, theme: 'default', swatches: [] } }; // Public methods $.extend($.fn, { minicolors: function(method, data) { switch(method) { // Destroy the control case 'destroy': $(this).each(function() { destroy($(this)); }); return $(this); // Hide the color picker case 'hide': hide(); return $(this); // Get/set opacity case 'opacity': // Getter if(data === undefined) { // Getter return $(this).attr('data-opacity'); } else { // Setter $(this).each(function() { updateFromInput($(this).attr('data-opacity', data)); }); } return $(this); // Get an RGB(A) object based on the current color/opacity case 'rgbObject': return rgbObject($(this), method === 'rgbaObject'); // Get an RGB(A) string based on the current color/opacity case 'rgbString': case 'rgbaString': return rgbString($(this), method === 'rgbaString'); // Get/set settings on the fly case 'settings': if(data === undefined) { return $(this).data('minicolors-settings'); } else { // Setter $(this).each(function() { var settings = $(this).data('minicolors-settings') || {}; destroy($(this)); $(this).minicolors($.extend(true, settings, data)); }); } return $(this); // Show the color picker case 'show': show($(this).eq(0)); return $(this); // Get/set the hex color value case 'value': if(data === undefined) { // Getter return $(this).val(); } else { // Setter $(this).each(function() { if(typeof(data) === 'object' && data !== 'null') { if(data.opacity) { $(this).attr('data-opacity', keepWithin(data.opacity, 0, 1)); } if(data.color) { $(this).val(data.color); } } else { $(this).val(data); } updateFromInput($(this)); }); } return $(this); // Initializes the control default: if(method !== 'create') data = method; $(this).each(function() { init($(this), data); }); return $(this); } } }); // Initialize input elements function init(input, settings) { var minicolors = $('
'); var defaults = $.minicolors.defaults; var size; var swatches; var swatch; var panel; var i; // Do nothing if already initialized if(input.data('minicolors-initialized')) return; // Handle settings settings = $.extend(true, {}, defaults, settings); // The wrapper minicolors .addClass('minicolors-theme-' + settings.theme) .toggleClass('minicolors-with-opacity', settings.opacity); // Custom positioning if(settings.position !== undefined) { $.each(settings.position.split(' '), function() { minicolors.addClass('minicolors-position-' + this); }); } // Input size if(settings.format === 'rgb') { size = settings.opacity ? '25' : '20'; } else { size = settings.keywords ? '11' : '7'; } // The input input .addClass('minicolors-input') .data('minicolors-initialized', false) .data('minicolors-settings', settings) .prop('size', size) .wrap(minicolors) .after( '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' ); // The swatch if(!settings.inline) { input.after(''); input.next('.minicolors-input-swatch').on('click', function(event) { event.preventDefault(); input.focus(); }); } // Prevent text selection in IE panel = input.parent().find('.minicolors-panel'); panel.on('selectstart', function() { return false; }).end(); // Swatches if(settings.swatches && settings.swatches.length !== 0) { panel.addClass('minicolors-with-swatches'); swatches = $('') .appendTo(panel); for(i = 0; i < settings.swatches.length; ++i) { swatch = settings.swatches[i]; swatch = isRgb(swatch) ? parseRgb(swatch, true) : hex2rgb(parseHex(swatch, true)); $('
  • ') .appendTo(swatches) .data('swatch-color', settings.swatches[i]) .find('.minicolors-swatch-color') .css({ backgroundColor: rgb2hex(swatch), opacity: swatch.a }); settings.swatches[i] = swatch; } } // Inline controls if(settings.inline) input.parent().addClass('minicolors-inline'); updateFromInput(input, false); input.data('minicolors-initialized', true); } // Returns the input back to its original state function destroy(input) { var minicolors = input.parent(); // Revert the input element input .removeData('minicolors-initialized') .removeData('minicolors-settings') .removeProp('size') .removeClass('minicolors-input'); // Remove the wrap and destroy whatever remains minicolors.before(input).remove(); } // Shows the specified dropdown panel function show(input) { var minicolors = input.parent(); var panel = minicolors.find('.minicolors-panel'); var settings = input.data('minicolors-settings'); // Do nothing if uninitialized, disabled, inline, or already open if( !input.data('minicolors-initialized') || input.prop('disabled') || minicolors.hasClass('minicolors-inline') || minicolors.hasClass('minicolors-focus') ) return; hide(); minicolors.addClass('minicolors-focus'); panel .stop(true, true) .fadeIn(settings.showSpeed, function() { if(settings.show) settings.show.call(input.get(0)); }); } // Hides all dropdown panels function hide() { $('.minicolors-focus').each(function() { var minicolors = $(this); var input = minicolors.find('.minicolors-input'); var panel = minicolors.find('.minicolors-panel'); var settings = input.data('minicolors-settings'); panel.fadeOut(settings.hideSpeed, function() { if(settings.hide) settings.hide.call(input.get(0)); minicolors.removeClass('minicolors-focus'); }); }); } // Moves the selected picker function move(target, event, animate) { var input = target.parents('.minicolors').find('.minicolors-input'); var settings = input.data('minicolors-settings'); var picker = target.find('[class$=-picker]'); var offsetX = target.offset().left; var offsetY = target.offset().top; var x = Math.round(event.pageX - offsetX); var y = Math.round(event.pageY - offsetY); var duration = animate ? settings.animationSpeed : 0; var wx, wy, r, phi; // Touch support if(event.originalEvent.changedTouches) { x = event.originalEvent.changedTouches[0].pageX - offsetX; y = event.originalEvent.changedTouches[0].pageY - offsetY; } // Constrain picker to its container if(x < 0) x = 0; if(y < 0) y = 0; if(x > target.width()) x = target.width(); if(y > target.height()) y = target.height(); // Constrain color wheel values to the wheel if(target.parent().is('.minicolors-slider-wheel') && picker.parent().is('.minicolors-grid')) { wx = 75 - x; wy = 75 - y; r = Math.sqrt(wx * wx + wy * wy); phi = Math.atan2(wy, wx); if(phi < 0) phi += Math.PI * 2; if(r > 75) { r = 75; x = 75 - (75 * Math.cos(phi)); y = 75 - (75 * Math.sin(phi)); } x = Math.round(x); y = Math.round(y); } // Move the picker if(target.is('.minicolors-grid')) { picker .stop(true) .animate({ top: y + 'px', left: x + 'px' }, duration, settings.animationEasing, function() { updateFromControl(input, target); }); } else { picker .stop(true) .animate({ top: y + 'px' }, duration, settings.animationEasing, function() { updateFromControl(input, target); }); } } // Sets the input based on the color picker values function updateFromControl(input, target) { function getCoords(picker, container) { var left, top; if(!picker.length || !container) return null; left = picker.offset().left; top = picker.offset().top; return { x: left - container.offset().left + (picker.outerWidth() / 2), y: top - container.offset().top + (picker.outerHeight() / 2) }; } var hue, saturation, brightness, x, y, r, phi; var hex = input.val(); var opacity = input.attr('data-opacity'); // Helpful references var minicolors = input.parent(); var settings = input.data('minicolors-settings'); var swatch = minicolors.find('.minicolors-input-swatch'); // Panel objects var grid = minicolors.find('.minicolors-grid'); var slider = minicolors.find('.minicolors-slider'); var opacitySlider = minicolors.find('.minicolors-opacity-slider'); // Picker objects var gridPicker = grid.find('[class$=-picker]'); var sliderPicker = slider.find('[class$=-picker]'); var opacityPicker = opacitySlider.find('[class$=-picker]'); // Picker positions var gridPos = getCoords(gridPicker, grid); var sliderPos = getCoords(sliderPicker, slider); var opacityPos = getCoords(opacityPicker, opacitySlider); // Handle colors if(target.is('.minicolors-grid, .minicolors-slider, .minicolors-opacity-slider')) { // Determine HSB values switch(settings.control) { case 'wheel': // Calculate hue, saturation, and brightness x = (grid.width() / 2) - gridPos.x; y = (grid.height() / 2) - gridPos.y; r = Math.sqrt(x * x + y * y); phi = Math.atan2(y, x); if(phi < 0) phi += Math.PI * 2; if(r > 75) { r = 75; gridPos.x = 69 - (75 * Math.cos(phi)); gridPos.y = 69 - (75 * Math.sin(phi)); } saturation = keepWithin(r / 0.75, 0, 100); hue = keepWithin(phi * 180 / Math.PI, 0, 360); brightness = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100); hex = hsb2hex({ h: hue, s: saturation, b: brightness }); // Update UI slider.css('backgroundColor', hsb2hex({ h: hue, s: saturation, b: 100 })); break; case 'saturation': // Calculate hue, saturation, and brightness hue = keepWithin(parseInt(gridPos.x * (360 / grid.width()), 10), 0, 360); saturation = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100); brightness = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100); hex = hsb2hex({ h: hue, s: saturation, b: brightness }); // Update UI slider.css('backgroundColor', hsb2hex({ h: hue, s: 100, b: brightness })); minicolors.find('.minicolors-grid-inner').css('opacity', saturation / 100); break; case 'brightness': // Calculate hue, saturation, and brightness hue = keepWithin(parseInt(gridPos.x * (360 / grid.width()), 10), 0, 360); saturation = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100); brightness = keepWithin(100 - Math.floor(sliderPos.y * (100 / slider.height())), 0, 100); hex = hsb2hex({ h: hue, s: saturation, b: brightness }); // Update UI slider.css('backgroundColor', hsb2hex({ h: hue, s: saturation, b: 100 })); minicolors.find('.minicolors-grid-inner').css('opacity', 1 - (brightness / 100)); break; default: // Calculate hue, saturation, and brightness hue = keepWithin(360 - parseInt(sliderPos.y * (360 / slider.height()), 10), 0, 360); saturation = keepWithin(Math.floor(gridPos.x * (100 / grid.width())), 0, 100); brightness = keepWithin(100 - Math.floor(gridPos.y * (100 / grid.height())), 0, 100); hex = hsb2hex({ h: hue, s: saturation, b: brightness }); // Update UI grid.css('backgroundColor', hsb2hex({ h: hue, s: 100, b: 100 })); break; } // Handle opacity if(settings.opacity) { opacity = parseFloat(1 - (opacityPos.y / opacitySlider.height())).toFixed(2); } else { opacity = 1; } updateInput(input, hex, opacity); } else { // Set swatch color swatch.find('span').css({ backgroundColor: hex, opacity: opacity }); // Handle change event doChange(input, hex, opacity); } } // Sets the value of the input and does the appropriate conversions // to respect settings, also updates the swatch function updateInput(input, value, opacity) { var rgb; // Helpful references var minicolors = input.parent(); var settings = input.data('minicolors-settings'); var swatch = minicolors.find('.minicolors-input-swatch'); if(settings.opacity) input.attr('data-opacity', opacity); // Set color string if(settings.format === 'rgb') { // Returns RGB(A) string // Checks for input format and does the conversion if(isRgb(value)) { rgb = parseRgb(value, true); } else { rgb = hex2rgb(parseHex(value, true)); } opacity = input.attr('data-opacity') === '' ? 1 : keepWithin(parseFloat(input.attr('data-opacity')).toFixed(2), 0, 1); if(isNaN(opacity) || !settings.opacity) opacity = 1; if(input.minicolors('rgbObject').a <= 1 && rgb && settings.opacity) { // Set RGBA string if alpha value = 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat(opacity) + ')'; } else { // Set RGB string (alpha = 1) value = 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')'; } } else { // Returns hex color // Checks for input format and does the conversion if(isRgb(value)) { value = rgbString2hex(value); } value = convertCase(value, settings.letterCase); } // Update value from picker input.val(value); // Set swatch color swatch.find('span').css({ backgroundColor: value, opacity: opacity }); // Handle change event doChange(input, value, opacity); } // Sets the color picker values from the input function updateFromInput(input, preserveInputValue) { var hex, hsb, opacity, keywords, alpha, value, x, y, r, phi; // Helpful references var minicolors = input.parent(); var settings = input.data('minicolors-settings'); var swatch = minicolors.find('.minicolors-input-swatch'); // Panel objects var grid = minicolors.find('.minicolors-grid'); var slider = minicolors.find('.minicolors-slider'); var opacitySlider = minicolors.find('.minicolors-opacity-slider'); // Picker objects var gridPicker = grid.find('[class$=-picker]'); var sliderPicker = slider.find('[class$=-picker]'); var opacityPicker = opacitySlider.find('[class$=-picker]'); // Determine hex/HSB values if(isRgb(input.val())) { // If input value is a rgb(a) string, convert it to hex color and update opacity hex = rgbString2hex(input.val()); alpha = keepWithin(parseFloat(getAlpha(input.val())).toFixed(2), 0, 1); if(alpha) { input.attr('data-opacity', alpha); } } else { hex = convertCase(parseHex(input.val(), true), settings.letterCase); } if(!hex){ hex = convertCase(parseInput(settings.defaultValue, true), settings.letterCase); } hsb = hex2hsb(hex); // Get array of lowercase keywords keywords = !settings.keywords ? [] : $.map(settings.keywords.split(','), function(a) { return $.trim(a.toLowerCase()); }); // Set color string if(input.val() !== '' && $.inArray(input.val().toLowerCase(), keywords) > -1) { value = convertCase(input.val()); } else { value = isRgb(input.val()) ? parseRgb(input.val()) : hex; } // Update input value if(!preserveInputValue) input.val(value); // Determine opacity value if(settings.opacity) { // Get from data-opacity attribute and keep within 0-1 range opacity = input.attr('data-opacity') === '' ? 1 : keepWithin(parseFloat(input.attr('data-opacity')).toFixed(2), 0, 1); if(isNaN(opacity)) opacity = 1; input.attr('data-opacity', opacity); swatch.find('span').css('opacity', opacity); // Set opacity picker position y = keepWithin(opacitySlider.height() - (opacitySlider.height() * opacity), 0, opacitySlider.height()); opacityPicker.css('top', y + 'px'); } // Set opacity to zero if input value is transparent if(input.val().toLowerCase() === 'transparent') { swatch.find('span').css('opacity', 0); } // Update swatch swatch.find('span').css('backgroundColor', hex); // Determine picker locations switch(settings.control) { case 'wheel': // Set grid position r = keepWithin(Math.ceil(hsb.s * 0.75), 0, grid.height() / 2); phi = hsb.h * Math.PI / 180; x = keepWithin(75 - Math.cos(phi) * r, 0, grid.width()); y = keepWithin(75 - Math.sin(phi) * r, 0, grid.height()); gridPicker.css({ top: y + 'px', left: x + 'px' }); // Set slider position y = 150 - (hsb.b / (100 / grid.height())); if(hex === '') y = 0; sliderPicker.css('top', y + 'px'); // Update panel color slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: hsb.s, b: 100 })); break; case 'saturation': // Set grid position x = keepWithin((5 * hsb.h) / 12, 0, 150); y = keepWithin(grid.height() - Math.ceil(hsb.b / (100 / grid.height())), 0, grid.height()); gridPicker.css({ top: y + 'px', left: x + 'px' }); // Set slider position y = keepWithin(slider.height() - (hsb.s * (slider.height() / 100)), 0, slider.height()); sliderPicker.css('top', y + 'px'); // Update UI slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: 100, b: hsb.b })); minicolors.find('.minicolors-grid-inner').css('opacity', hsb.s / 100); break; case 'brightness': // Set grid position x = keepWithin((5 * hsb.h) / 12, 0, 150); y = keepWithin(grid.height() - Math.ceil(hsb.s / (100 / grid.height())), 0, grid.height()); gridPicker.css({ top: y + 'px', left: x + 'px' }); // Set slider position y = keepWithin(slider.height() - (hsb.b * (slider.height() / 100)), 0, slider.height()); sliderPicker.css('top', y + 'px'); // Update UI slider.css('backgroundColor', hsb2hex({ h: hsb.h, s: hsb.s, b: 100 })); minicolors.find('.minicolors-grid-inner').css('opacity', 1 - (hsb.b / 100)); break; default: // Set grid position x = keepWithin(Math.ceil(hsb.s / (100 / grid.width())), 0, grid.width()); y = keepWithin(grid.height() - Math.ceil(hsb.b / (100 / grid.height())), 0, grid.height()); gridPicker.css({ top: y + 'px', left: x + 'px' }); // Set slider position y = keepWithin(slider.height() - (hsb.h / (360 / slider.height())), 0, slider.height()); sliderPicker.css('top', y + 'px'); // Update panel color grid.css('backgroundColor', hsb2hex({ h: hsb.h, s: 100, b: 100 })); break; } // Fire change event, but only if minicolors is fully initialized if(input.data('minicolors-initialized')) { doChange(input, value, opacity); } } // Runs the change and changeDelay callbacks function doChange(input, value, opacity) { var settings = input.data('minicolors-settings'); var lastChange = input.data('minicolors-lastChange'); var obj, sel, i; // Only run if it actually changed if(!lastChange || lastChange.value !== value || lastChange.opacity !== opacity) { // Remember last-changed value input.data('minicolors-lastChange', { value: value, opacity: opacity }); // Check and select applicable swatch if(settings.swatches && settings.swatches.length !== 0) { if(!isRgb(value)) { obj = hex2rgb(value); } else { obj = parseRgb(value, true); } sel = -1; for(i = 0; i < settings.swatches.length; ++i) { if(obj.r === settings.swatches[i].r && obj.g === settings.swatches[i].g && obj.b === settings.swatches[i].b && obj.a === settings.swatches[i].a) { sel = i; break; } } input.parent().find('.minicolors-swatches .minicolors-swatch').removeClass('selected'); if(sel !== -1) { input.parent().find('.minicolors-swatches .minicolors-swatch').eq(i).addClass('selected'); } } // Fire change event if(settings.change) { if(settings.changeDelay) { // Call after a delay clearTimeout(input.data('minicolors-changeTimeout')); input.data('minicolors-changeTimeout', setTimeout(function() { settings.change.call(input.get(0), value, opacity); }, settings.changeDelay)); } else { // Call immediately settings.change.call(input.get(0), value, opacity); } } input.trigger('change').trigger('input'); } } // Generates an RGB(A) object based on the input's value function rgbObject(input) { var rgb, opacity = $(input).attr('data-opacity'); if( isRgb($(input).val()) ) { rgb = parseRgb($(input).val(), true); } else { var hex = parseHex($(input).val(), true); rgb = hex2rgb(hex); } if( !rgb ) return null; if( opacity !== undefined ) $.extend(rgb, { a: parseFloat(opacity) }); return rgb; } // Generates an RGB(A) string based on the input's value function rgbString(input, alpha) { var rgb, opacity = $(input).attr('data-opacity'); if( isRgb($(input).val()) ) { rgb = parseRgb($(input).val(), true); } else { var hex = parseHex($(input).val(), true); rgb = hex2rgb(hex); } if( !rgb ) return null; if( opacity === undefined ) opacity = 1; if( alpha ) { return 'rgba(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ', ' + parseFloat(opacity) + ')'; } else { return 'rgb(' + rgb.r + ', ' + rgb.g + ', ' + rgb.b + ')'; } } // Converts to the letter case specified in settings function convertCase(string, letterCase) { return letterCase === 'uppercase' ? string.toUpperCase() : string.toLowerCase(); } // Parses a string and returns a valid hex string when possible function parseHex(string, expand) { string = string.replace(/^#/g, ''); if(!string.match(/^[A-F0-9]{3,6}/ig)) return ''; if(string.length !== 3 && string.length !== 6) return ''; if(string.length === 3 && expand) { string = string[0] + string[0] + string[1] + string[1] + string[2] + string[2]; } return '#' + string; } // Parses a string and returns a valid RGB(A) string when possible function parseRgb(string, obj) { var values = string.replace(/[^\d,.]/g, ''); var rgba = values.split(','); rgba[0] = keepWithin(parseInt(rgba[0], 10), 0, 255); rgba[1] = keepWithin(parseInt(rgba[1], 10), 0, 255); rgba[2] = keepWithin(parseInt(rgba[2], 10), 0, 255); if(rgba[3]) { rgba[3] = keepWithin(parseFloat(rgba[3], 10), 0, 1); } // Return RGBA object if( obj ) { if (rgba[3]) { return { r: rgba[0], g: rgba[1], b: rgba[2], a: rgba[3] }; } else { return { r: rgba[0], g: rgba[1], b: rgba[2] }; } } // Return RGBA string if(typeof(rgba[3]) !== 'undefined' && rgba[3] <= 1) { return 'rgba(' + rgba[0] + ', ' + rgba[1] + ', ' + rgba[2] + ', ' + rgba[3] + ')'; } else { return 'rgb(' + rgba[0] + ', ' + rgba[1] + ', ' + rgba[2] + ')'; } } // Parses a string and returns a valid color string when possible function parseInput(string, expand) { if(isRgb(string)) { // Returns a valid rgb(a) string return parseRgb(string); } else { return parseHex(string, expand); } } // Keeps value within min and max function keepWithin(value, min, max) { if(value < min) value = min; if(value > max) value = max; return value; } // Checks if a string is a valid RGB(A) string function isRgb(string) { var rgb = string.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i); return (rgb && rgb.length === 4) ? true : false; } // Function to get alpha from a RGB(A) string function getAlpha(rgba) { rgba = rgba.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+(\.\d{1,2})?|\.\d{1,2})[\s+]?/i); return (rgba && rgba.length === 6) ? rgba[4] : '1'; } // Converts an HSB object to an RGB object function hsb2rgb(hsb) { var rgb = {}; var h = Math.round(hsb.h); var s = Math.round(hsb.s * 255 / 100); var v = Math.round(hsb.b * 255 / 100); if(s === 0) { rgb.r = rgb.g = rgb.b = v; } else { var t1 = v; var t2 = (255 - s) * v / 255; var t3 = (t1 - t2) * (h % 60) / 60; if(h === 360) h = 0; if(h < 60) { rgb.r = t1; rgb.b = t2; rgb.g = t2 + t3; } else if(h < 120) {rgb.g = t1; rgb.b = t2; rgb.r = t1 - t3; } else if(h < 180) {rgb.g = t1; rgb.r = t2; rgb.b = t2 + t3; } else if(h < 240) {rgb.b = t1; rgb.r = t2; rgb.g = t1 - t3; } else if(h < 300) {rgb.b = t1; rgb.g = t2; rgb.r = t2 + t3; } else if(h < 360) {rgb.r = t1; rgb.g = t2; rgb.b = t1 - t3; } else { rgb.r = 0; rgb.g = 0; rgb.b = 0; } } return { r: Math.round(rgb.r), g: Math.round(rgb.g), b: Math.round(rgb.b) }; } // Converts an RGB string to a hex string function rgbString2hex(rgb){ rgb = rgb.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i); return (rgb && rgb.length === 4) ? '#' + ('0' + parseInt(rgb[1],10).toString(16)).slice(-2) + ('0' + parseInt(rgb[2],10).toString(16)).slice(-2) + ('0' + parseInt(rgb[3],10).toString(16)).slice(-2) : ''; } // Converts an RGB object to a hex string function rgb2hex(rgb) { var hex = [ rgb.r.toString(16), rgb.g.toString(16), rgb.b.toString(16) ]; $.each(hex, function(nr, val) { if(val.length === 1) hex[nr] = '0' + val; }); return '#' + hex.join(''); } // Converts an HSB object to a hex string function hsb2hex(hsb) { return rgb2hex(hsb2rgb(hsb)); } // Converts a hex string to an HSB object function hex2hsb(hex) { var hsb = rgb2hsb(hex2rgb(hex)); if(hsb.s === 0) hsb.h = 360; return hsb; } // Converts an RGB object to an HSB object function rgb2hsb(rgb) { var hsb = { h: 0, s: 0, b: 0 }; var min = Math.min(rgb.r, rgb.g, rgb.b); var max = Math.max(rgb.r, rgb.g, rgb.b); var delta = max - min; hsb.b = max; hsb.s = max !== 0 ? 255 * delta / max : 0; if(hsb.s !== 0) { if(rgb.r === max) { hsb.h = (rgb.g - rgb.b) / delta; } else if(rgb.g === max) { hsb.h = 2 + (rgb.b - rgb.r) / delta; } else { hsb.h = 4 + (rgb.r - rgb.g) / delta; } } else { hsb.h = -1; } hsb.h *= 60; if(hsb.h < 0) { hsb.h += 360; } hsb.s *= 100/255; hsb.b *= 100/255; return hsb; } // Converts a hex string to an RGB object function hex2rgb(hex) { hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16); return { r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF) }; } // Handle events $([document, top.document]) // Hide on clicks outside of the control .on('mousedown.minicolors touchstart.minicolors', function(event) { if(!$(event.target).parents().add(event.target).hasClass('minicolors')) { hide(); } }) // Start moving .on('mousedown.minicolors touchstart.minicolors', '.minicolors-grid, .minicolors-slider, .minicolors-opacity-slider', function(event) { var target = $(this); event.preventDefault(); $(event.delegateTarget).data('minicolors-target', target); move(target, event, true); }) // Move pickers .on('mousemove.minicolors touchmove.minicolors', function(event) { var target = $(event.delegateTarget).data('minicolors-target'); if(target) move(target, event); }) // Stop moving .on('mouseup.minicolors touchend.minicolors', function() { $(this).removeData('minicolors-target'); }) // Selected a swatch .on('click.minicolors', '.minicolors-swatches li', function(event) { event.preventDefault(); var target = $(this), input = target.parents('.minicolors').find('.minicolors-input'), color = target.data('swatch-color'); updateInput(input, color, getAlpha(color)); updateFromInput(input); }) // Show panel when swatch is clicked .on('mousedown.minicolors touchstart.minicolors', '.minicolors-input-swatch', function(event) { var input = $(this).parent().find('.minicolors-input'); event.preventDefault(); show(input); }) // Show on focus .on('focus.minicolors', '.minicolors-input', function() { var input = $(this); if(!input.data('minicolors-initialized')) return; show(input); }) // Update value on blur .on('blur.minicolors', '.minicolors-input', function() { var input = $(this); var settings = input.data('minicolors-settings'); var keywords; var hex; var rgba; var swatchOpacity; var value; if(!input.data('minicolors-initialized')) return; // Get array of lowercase keywords keywords = !settings.keywords ? [] : $.map(settings.keywords.split(','), function(a) { return $.trim(a.toLowerCase()); }); // Set color string if(input.val() !== '' && $.inArray(input.val().toLowerCase(), keywords) > -1) { value = input.val(); } else { // Get RGBA values for easy conversion if(isRgb(input.val())) { rgba = parseRgb(input.val(), true); } else { hex = parseHex(input.val(), true); rgba = hex ? hex2rgb(hex) : null; } // Convert to format if(rgba === null) { value = settings.defaultValue; } else if(settings.format === 'rgb') { value = settings.opacity ? parseRgb('rgba(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ',' + input.attr('data-opacity') + ')') : parseRgb('rgb(' + rgba.r + ',' + rgba.g + ',' + rgba.b + ')'); } else { value = rgb2hex(rgba); } } // Update swatch opacity swatchOpacity = settings.opacity ? input.attr('data-opacity') : 1; if(value.toLowerCase() === 'transparent') swatchOpacity = 0; input .closest('.minicolors') .find('.minicolors-input-swatch > span') .css('opacity', swatchOpacity); // Set input value input.val(value); // Is it blank? if(input.val() === '') input.val(parseInput(settings.defaultValue, true)); // Adjust case input.val(convertCase(input.val(), settings.letterCase)); }) // Handle keypresses .on('keydown.minicolors', '.minicolors-input', function(event) { var input = $(this); if(!input.data('minicolors-initialized')) return; switch(event.keyCode) { case 9: // tab hide(); break; case 13: // enter case 27: // esc hide(); input.blur(); break; } }) // Update on keyup .on('keyup.minicolors', '.minicolors-input', function() { var input = $(this); if(!input.data('minicolors-initialized')) return; updateFromInput(input, true); }) // Update on paste .on('paste.minicolors', '.minicolors-input', function() { var input = $(this); if(!input.data('minicolors-initialized')) return; setTimeout(function() { updateFromInput(input, true); }, 1); }); })); ================================================ FILE: app/lib/minicolors/package.json ================================================ { "name": "@claviska/jquery-minicolors", "version": "2.2.6", "homepage": "https://github.com/claviska/jquery-minicolors", "author": "Cory LaViska", "description": "jQuery MiniColors Plugin", "main": "jquery.minicolors.js", "keywords": [ "jquery", "colorpicker" ], "license": "MIT", "dependencies": { "jquery": ">= 1.7.x" }, "devDependencies": { "del": "^2.2.0", "gulp": "^3.9.1", "gulp-help": "^1.6.1", "gulp-rename": "^1.2.2", "gulp-uglify": "^1.5.3" }, "repository": { "type": "git", "url": "https://github.com/claviska/jquery-minicolors.git" }, "bugs": { "url": "https://github.com/claviska/jquery-minicolors/issues" }, "scripts": {} } ================================================ FILE: app/lib/minicolors/without-bootstrap.html ================================================ jQuery MiniColors

    MiniColors Demo (without Bootstrap)

    « Back to the Bootstrap demo

    Control Types

    Input Modes




    Positions

    RGB(A)



    …and more!







    ================================================ FILE: app/main.js ================================================ const electron = require('electron') // Module to control application life. const app = electron.app // Module to create native browser window. const BrowserWindow = electron.BrowserWindow const ipcMain = electron.ipcMain; const path = require('path'); const url = require('url'); const util = require('util'); const fs = require('fs'); const spawn = require('child_process').spawn; const exec = require('child_process').exec; const settingsPath = path.join(app.getPath('userData'),'app_db.json'); const low = require('lowdb'); require('fix-path')(); var which = require('which'); var ffbinaries = require('ffbinaries'); // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let mainWindow let ffmpeg_ps let db // var appData = app.getPath("userData"); function createWindow (needs_ffmpeg) { // Create the browser window. // mainWindow = new BrowserWindow({width: 800, height: 600}) var externalDisplay = electron.screen.getPrimaryDisplay() var width = 800; var height = 600; if (externalDisplay) { width = externalDisplay.bounds.width*0.8; height = externalDisplay.bounds.height*0.8; } mainWindow = new BrowserWindow({ // x:windowSettings.x, // y:windowSettings.y, // width: windowSettings.width, // height: windowSettings.height, width:width, height:height, minWidth:800, minHeight:600 // titleBarStyle:"hidden" }) // and load the index.html of the app. mainWindow.loadURL(url.format({ pathname: path.join(__dirname, needs_ffmpeg ? 'ffmpeg.html':'index.html'), protocol: 'file:', slashes: true })) // Open the DevTools. // mainWindow.webContents.openDevTools() // Emitted when the window is closed. mainWindow.on('closed', function () { // Dereference the window object, usually you would store windows // in an array if your app supports multi windows, this is the time // when you should delete the corresponding element. mainWindow = null }) } // This method will be called when Electron has finished // initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. var ffmpeg_path = false; var ffprobe_path = false; app.on('ready', function(){ db = low(settingsPath); db.defaults({ ffmpeg: {ffmpeg:false, ffprobe:false}, window:{x:0, y:0, width:800, height:600}}).write(); var ffmpeg_store = db.get('ffmpeg').value(); console.log(ffmpeg_store); var opts = {}; if(ffmpeg_store.ffmpeg){ opts = {path:path.dirname(ffmpeg_store.ffmpeg)} } which('ffmpeg', opts, function (er, ffmpeg) { ffmpeg_path = (!er && ffmpeg) ? ffmpeg : false; var opts = {}; if(ffmpeg_store.ffprobe){ opts = {path:path.dirname(ffmpeg_store.ffprobe)} } which('ffprobe', opts, function (er, ffprobe) { ffprobe_path = (!er && ffprobe) ? ffprobe : false; console.log(ffmpeg_path, ffprobe_path); createWindow(!ffmpeg_path || !ffprobe_path); }); }); }) // Quit when all windows are closed. app.on('window-all-closed', function () { // On OS X it is common for applications and their menu bar // to stay active until the user quits explicitly with Cmd + Q // if (process.platform !== 'darwin') { app.quit() // } }) app.on('activate', function () { // On OS X it's common to re-create a window in the app when the // dock icon is clicked and there are no other windows open. if (mainWindow === null) { createWindow() } }) ipcMain.on('install_ffmpeg',function(event,input){ console.log("INSTALL"); var platform = ffbinaries.detectPlatform(); var dest = path.join(app.getPath("userData"), "ffmpeg"); ffbinaries.downloadFiles(['ffmpeg','ffprobe'], {quiet: true, destination: dest}, function () { console.log('Downloaded binaries for ' + platform + '.'); ffmpeg_path = dest+"/ffmpeg"; ffprobe_path = dest+"/ffprobe"; db.set('ffmpeg.ffmpeg', ffmpeg_path) .set('ffmpeg.ffprobe', ffprobe_path) .write() mainWindow.loadURL(url.format({ pathname: path.join(__dirname, 'index.html'), protocol: 'file:', slashes: true })) // event.sender.send('ffmpeg_installed', platform); }); }); // In this file you can include the rest of your app's specific main process // code. You can also put them in separate files and require them here. ipcMain.on('probeInput', (event, input) => { console.log("PROBE", ffprobe_path); var cmd = "\""+ffprobe_path+"\" -v quiet -print_format json -show_format -show_streams \""+input+"\""; exec(cmd, function(so,se,e) { // console.log(so,se,e); var metadata = JSON.parse(se); event.sender.send('probeResult', metadata); }); }); ipcMain.on('getPalette', (event, input, prefs) => { // console.log(prefs); // var input = prefs.file.input; var w = prefs.dimensions.width || 320; var h = prefs.dimensions.height || 240; var fps = prefs.fps || 24; var stats = prefs.color.stats_mode || 'full'; // var colors = prefs.color.colors || 256; var transparency = (prefs.color.alpha?1:0) || 0; var colors = prefs.color.count || 256; var scaleCmd = "scale="+w+":"+h; var vf = util.format("fps=%s,%s:flags=lanczos,palettegen=stats_mode=%s:max_colors=%s:reserve_transparent=%s", fps, scaleCmd, stats, colors, transparency); if(ffmpeg_ps) ffmpeg_ps.kill(); ffmpeg_ps = spawn(ffmpeg_path, ["-i", input, "-vf", vf, "-f", "image2", "-vcodec", "png", "pipe:1"]) var data = []; ffmpeg_ps.stdout.on('data',function(d){ data.push(d); }); ffmpeg_ps.stderr.on('data',function(d){ // console.log("stderr",d.toString()); }); ffmpeg_ps.on('close',function(){ event.sender.send('paletteResult', Buffer.concat(data).toString('base64')); }); }) ipcMain.on('cancelProcess', (event,opts) => { if(ffmpeg_ps){ ffmpeg_ps.kill(); } }); var canceled = false; ipcMain.on('cancel_export', (event, opts) => { canceled=true; if(ffmpeg_ps){ ffmpeg_ps.kill(); } if(opts.remove){ //remove the partially exported file console.log("REMOVE", opts.remove); fs.unlinkSync(opts.remove); } }); ipcMain.on('getThumbnail', (event, input, palette, time, settings) => { // .frames(1) // .duration(1) // .complexFilter("fps="+fps+","+scaleCmd+":flags=lanczos[x];[x][1:v]paletteuse=dither="+dither) // .outputFormat("gif") // var settings = {fps:30,dither:'true'}; // var gif = "fps="+settings.fps+",flags=lanczos[x];[x][1:v]paletteuse=dither="+settings.dither; var w = settings.dimensions.width || 320; var h = settings.dimensions.height || 240; var fps = settings.fps || 24; var scaleCmd = "scale="+w+":"+h; var dither = settings.color.dither ? ('bayer:bayer_scale='+settings.color.dither_scale) : 'none'; var diff_mode = settings.color.diff_mode ? settings.color.diff_mode : "rectangle"; var diff_mode = settings.loop ? settings.loop : 0; var vf = util.format("fps=%s,%s:flags=lanczos [x];[x][1:v]paletteuse=dither=%s:diff_mode=%s", fps, scaleCmd, dither, diff_mode, loop); console.log(vf); if(ffmpeg_ps) ffmpeg_ps.kill(); ffmpeg_ps = spawn(ffmpeg_path, [ "-ss", time, "-i", input, "-i", "pipe:0", "-t", 1, "-lavfi", vf, "-frames:v", 1, "-an", "-f", "image2", "-vcodec", "gif", "pipe:1" ]) var data = []; ffmpeg_ps.stdout.on('data',function(d){ // console.log("stdout",d.toString()); data.push(d); }); ffmpeg_ps.stderr.on('data',function(d){ // console.log("stderr",d.toString()); }); ffmpeg_ps.on('close',function(){ event.sender.send('thumbnailResult', Buffer.concat(data).toString('base64')); console.log('done'); }); ffmpeg_ps.stdin.write(Buffer.from(palette, 'base64')); ffmpeg_ps.stdin.end(); // exec("ffmpeg -ss "+time+" -i "+input+" -t 1 -frames:v 1 -f image2 -vcodec png -", function(so,se,e) { // // console.log(so,se,e); // console.log(so); // event.sender.send('thumbnailResult', new Buffer(se, 'binary').toString('base64')); // }); }); ipcMain.on('exportGif', (event, input, output, palette, settings) => { var stats = settings.color.stats_mode || 'full'; var dither = settings.color.dither ? ('bayer:bayer_scale='+settings.color.dither_scale) : 'none'; var colors = settings.color.colors || 256; var fps = settings.fps || 10; var w = settings.dimensions.width || 320; var h = settings.dimensions.height || 240; var scaleCmd = "scale="+w+":"+h; var vf = util.format("fps=%s,%s:flags=lanczos [x];[x][1:v]paletteuse=dither=%s", fps, scaleCmd, dither); // var filters = util.format("fps=%s,%s:flags=lanczos[x];[x][1:v]paletteuse=dither=%s", fps, scaleCmd, dither); if(ffmpeg_ps) ffmpeg_ps.kill(); ffmpeg_ps = spawn(ffmpeg_path, [ "-i", input, "-i", "pipe:0", "-lavfi", vf, "-an", "-f", "gif", output ]) // var data = []; ffmpeg_ps.stdout.on('data',function(d){ console.log("stdout",d.toString()); // data.push(d); }); ffmpeg_ps.stderr.on('data',function(d){ // var time = /time=(\d+)\:(\d+)\:(\d+)\.(\d+)\s+/.exec(d.toString()); var progress = parseProgressLine(d.toString()); console.log(progress); // if(time && time.length >= 5){ if(progress && progress.time){ // var time = (parseInt(time[1])*3600) + (parseInt(time[2])*60) + parseFloat(time[3] + "." + time[4]); // var sec = timemarkToSeconds(progress.time); // var size = parseInt(progress.size.replace('kB',''))*1000; var progress_obj = { sec: timemarkToSeconds(progress.time), size: progress.size ? parseInt(progress.size.replace('kB',''))*1000 : 0 } event.sender.send('export_progress', progress_obj); } }); ffmpeg_ps.on('close',function(){ // event.sender.send('thumbnailResult', Buffer.concat(data).toString('base64')); console.log('done'); if(canceled){ canceled=false; event.sender.send('export_canceled', {}); }else{ event.sender.send('export_finished', getFilesizeInBytes(output)); } }); ffmpeg_ps.stdin.write(Buffer.from(palette, 'base64')); ffmpeg_ps.stdin.end(); }); function timemarkToSeconds(timemark) { if (typeof timemark === 'number') { return timemark; } if (timemark.indexOf(':') === -1 && timemark.indexOf('.') >= 0) { return Number(timemark); } var parts = timemark.split(':'); // add seconds var secs = Number(parts.pop()); if (parts.length) { // add minutes secs += Number(parts.pop()) * 60; } if (parts.length) { // add hours secs += Number(parts.pop()) * 3600; } return secs; } function parseProgressLine(line) { var progress = {}; // Remove all spaces after = and trim line = line.replace(/=\s+/g, '=').trim(); var progressParts = line.split(' '); // Split every progress part by "=" to get key and value for(var i = 0; i < progressParts.length; i++) { var progressSplit = progressParts[i].split('=', 2); var key = progressSplit[0]; var value = progressSplit[1]; // This is not a progress line if(typeof value === 'undefined') return null; progress[key] = value; } return progress; } function getFilesizeInBytes(filename) { const stats = fs.statSync(filename) const fileSizeInBytes = stats.size return fileSizeInBytes } ================================================ FILE: app/package.json ================================================ { "name": "GifTuna", "build": { "appId": "com.ndmweb.giftuna", "mac": { "category": "public.app-category.image-tools", "icon": "../resources/logo-hires-v2.icns" } }, "version": "1.0.7", "main": "main.js", "dependencies": { "angular": "^1.6.4", "ffbinaries": "^1.0.1", "fix-path": "^2.1.0", "jquery": "^3.2.1", "lowdb": "^0.16.2", "which": "^1.2.14" } } ================================================ FILE: app/preview.html ================================================ GifTuna ji ================================================ FILE: app/renderer.js ================================================ // This file is required by the index.html file and will // be executed in the renderer process for that window. // All of the Node.js APIs are available in this process. const electron = require('electron') const {ipcRenderer} = electron const {dialog} = electron.remote const {shell} = require('electron') const url = require('url') const path = require('path') require("./lib/minicolors/jquery.minicolors.js"); global.jQuery = global.$ = require('jquery'); global.angular = require('angular'); var app = angular.module('giftuna',[]); app.controller('installFfmpeg',function($scope){ $scope.ffmpeg_click = function(){ shell.openExternal("http://ffmpeg.org"); } $scope.quit = function(){ electron.remote.app.quit(); } $scope.install = function(){ $scope.installing=true; ipcRenderer.send('install_ffmpeg', {}); } ipcRenderer.on('ffmpeg_installed',function(ev,data){ console.log('ffmpeg_installed'); // window.location.href = "/index.html"; $scope.installing=false; $scope.$apply(); }); //open links externally by default // $('a[href^="http"]').on('click',function(event) { // console.log("A"); // event.preventDefault(); // shell.openExternal(this.href); // }); }); app.controller('gifSettings',function($scope,$filter,$timeout,$rootScope){ $scope.status = { state:0, export:{progress:0,size:0,path:null} } $scope.frames = { current:0, min:0, max:100 } $scope.defaults = { file: { input:null }, dimensions: { original_width:320, original_height:240, width:320, height:240, lock:true }, fps:24, color: { stats_mode:"diff", diff_mode: "rectangle", dither:true, count: 256, dither_scale:3, alpha:false } }; $scope.settings = angular.copy($scope.defaults); $scope.color_value = 256; $scope.$watch('color_value',function(nv){ if(nv){ $scope.settings.color.count = Number(nv); } }); $scope.$watch('settings.color.count',function(nv){ if(nv){ $scope.color_value = Number(nv); } }) $scope.settings.dimensions.ratio = $scope.settings.dimensions.original_height/$scope.settings.dimensions.original_width; var prom; $scope.$watch('frames.current',function(nv,ov){ if(nv!=ov && $scope.status.state==5){ $scope.refreshThumbnail(); } }); $rootScope.$on('colorPaletteChange',function(){ $scope.refreshThumbnail(); }); $scope.reveal = function(){ console.log($scope.status.export.path); shell.showItemInFolder($scope.status.export.path); } $scope.preview = function(){ window.open(url.format({ pathname: $scope.status.export.path, protocol: 'file:', slashes: true })); } $scope.export = function(){ var base = path.parse($scope.settings.file.input.path); var output = path.join(base.dir, base.name+'.gif'); dialog.showSaveDialog({title:"Export GIF", defaultPath: output, buttonLabel:"Export"}, function(outputFile){ console.log(outputFile); if(outputFile){ $scope.status.export = {progress:0, size:0, path:outputFile}; $scope.status.state = 4; $scope.$apply(); ipcRenderer.send('exportGif', $scope.settings.file.input.path, outputFile, $scope.palette, $scope.settings); } // $rootScope.exportStatus.filepath = file; // $rootScope.exportStatus.filename = path.basename(file); // $rootScope.exportStatus.status = 1; // $rootScope.exportStatus.totalFrames = Math.floor($rootScope.currentSource.stream.duration * $rootScope.prefs.fps); // ipcRenderer.send('exportGif', $rootScope.currentSource.source.file.path, file, $rootScope.colorPalette, $rootScope.prefs); }); } $scope.cancelExport = function(){ $scope.status.export.canceling=true; ipcRenderer.send('cancel_export', {remove:$scope.status.export.path}); } $scope.widthChange = function(){ if($scope.settings.dimensions.width > 0 && $scope.settings.dimensions.lock){ var ratio = $scope.settings.dimensions.original_height/$scope.settings.dimensions.original_width; $scope.settings.dimensions.height = Math.round($scope.settings.dimensions.width*ratio); } // if(prom) $timeout.cancel(prom); // prom = $timeout(function(){ // $scope.refreshThumbnail(); // },2000); } $scope.heightChange = function(){ if($scope.settings.dimensions.height > 0 && $scope.settings.dimensions.lock){ var ratio = $scope.settings.dimensions.original_width/$scope.settings.dimensions.original_height; $scope.settings.dimensions.width = Math.round($scope.settings.dimensions.height*ratio); } } $scope.cancel = function(reset){ ipcRenderer.send('cancelProcess', {}); if(reset){ $scope.status.state=0; $scope.settings.file = {input:null}; $scope.palette = null; $scope.thumbnail = null; } } $scope.refreshFps = function(){ if($scope.stored.fps != $scope.settings.fps){ //$scope.frames.max = Math.floor($scope.settings.probe.duration * $scope.settings.fps); // if($scope.frames.current > $scope.frames.max){ // $scope.frames.current = $scope.frames.max; // } $scope.refreshThumbnail(); } } $scope.refreshDimension = function(key){ if($scope.stored.dimensions[key] != $scope.settings.dimensions[key]){ console.log('diff'); // if(prom) $timeout.cancel(prom); // prom = $timeout(function(){ $scope.refreshThumbnail(); // },2000); } } $scope.exportDone = function(){ $scope.status.state=5; $scope.status.export = {progress:0, size:0, path:null}; } $scope.refreshPalette = function(){ $scope.thumbnail = null; $scope.palette = null; $scope.cancel(); $scope.status.state=2; ipcRenderer.send('getPalette', $scope.settings.file.input.path, $scope.settings) } $scope.refreshThumbnail = function(){ $scope.thumbnail = null; $scope.status.state=3; var time = $scope.frames.current; ipcRenderer.send('getThumbnail', $scope.settings.file.input.path, $scope.palette, time, $scope.settings) } ipcRenderer.on('export_canceled',function(ev,progress){ console.log("CANCELED"); $scope.status.export.canceling=false; $scope.exportDone(); $scope.$apply(); }); ipcRenderer.on('export_progress',function(ev,progress){ console.log("Progress", progress); var p = (progress.sec/$scope.settings.probe.duration)*100; $scope.status.export.progress = p; $scope.status.export.size = progress.size; $scope.$apply(); }); ipcRenderer.on('export_finished',function(ev,finalsize){ console.log("DONE!"); $scope.status.export.progress = 100; $scope.status.export.size = finalsize; // $scope.status.state = 5; $scope.$apply(); }); ipcRenderer.on('probeResult', (event, probe) => { console.log(probe); var videoStream = probe.streams.find(function(it){return it.codec_type=='video'; }); if(!videoStream){ console.error("No video stream found"); return; } ; $scope.frames.max = (Math.floor(videoStream.duration * 10) / 10).toFixed(1) - 0.1; //videoStream ? Math.floor(videoStream.duration * $scope.settings.fps) : 0; $scope.settings.probe = {duration:videoStream.duration, rate:(videoStream.r_frame_rate||videoStream.avg_frame_rate)} $scope.settings.dimensions.width = videoStream.width; $scope.settings.dimensions.height = videoStream.height; $scope.settings.dimensions.original_width = videoStream.width; $scope.settings.dimensions.original_height = videoStream.height; $scope.settings.dimensions.ratio = videoStream.width/videoStream.height; $scope.settings.fps = parseInt($filter('framerate')((videoStream.r_frame_rate||videoStream.avg_frame_rate), true)); //get thumbnail $scope.refreshPalette(); // $scope.status.state=2; // ipcRenderer.send('getPalette', $scope.settings.file.input.path, $scope.settings) $scope.$apply(); }); ipcRenderer.on('paletteResult', (event, paletteResult) => { if($scope.status.state==2){ $scope.palette = paletteResult; $scope.status.state=3; var time = $scope.frames.current; ipcRenderer.send('getThumbnail', $scope.settings.file.input.path, $scope.palette, time, $scope.settings) $scope.$apply(); } }); ipcRenderer.on('thumbnailResult', (event, thumbnailResult) => { $scope.thumbnail = 'data:image/gif;base64,'+thumbnailResult; $scope.status.state=5; $scope.stored = angular.copy($scope.settings); $scope.$apply(); }); $scope.$watch('settings.file.input',function(nv){ //reset file input if(nv){ $scope.frames.current=0; $scope.status.state=1; $scope.palette = null; $scope.thumbnail = null; $scope.settings.color = angular.copy($scope.defaults.color); ipcRenderer.send('probeInput', nv.path) } }); }); app.filter('filesize',function(){ return function(size){ var i = Math.floor( Math.log(size) / Math.log(1000) ); return size > 0 ? ( size / Math.pow(1000, i) ).toFixed(2) * 1 + ' ' + ['B', 'kB', 'MB', 'GB', 'TB'][i] : '-'; } }) app.filter('framerate', function(){ return function(input, suffix){ if(!input){ return '-'; } var fr = input.split('/'); var r = (parseInt(fr[0])/parseInt(fr[1])); if(suffix){ return r+' fps'; } return r; //scope.frames = Math.ceil(nv*rate); } }) .filter('ratio', function(){ return function(x){ var tolerance = 1.0E-6; var h1=1; var h2=0; var k1=0; var k2=1; var b = x; do { var a = Math.floor(b); var aux = h1; h1 = a*h1+h2; h2 = aux; aux = k1; k1 = a*k1+k2; k2 = aux; b = 1/(b-a); } while (Math.abs(x-h1/k1) > x*tolerance); return h1+":"+k1; } }) app.directive('inputSelect',function(){ return { require:'ngModel', link: function(scope,ele,attr,ngModelCtl){ var $file = $(""); $file.on('change',function(e){ var file = $(this).get(0).files[0]; console.log(file); ngModelCtl.$setViewValue(file); ngModelCtl.$render(); $(this).val(''); }); ele.on('click',function(e){ console.log('click'); $file.trigger('click'); }); } } }) app.directive('pixelPalette', function($timeout,$rootScope){ return { // template:'', templateUrl: 'tpl/palette.html', require: 'ngModel', scope: { ngModel:'=', maxColors:'=' }, link: function(scope,ele,attr,ngModelCtl){ scope.pixels = scope.ngModel ? read_palette(scope.ngModel) : []; scope.rgb = {}; scope.$watch('ngModel',function(nv,ov){ if(nv && nv!=ov){ scope.pixels = read_palette(nv); } if(nv==null){ scope.pixels = []; } }) // scope.hexPattern = new RegExp(/^0x[0-9A-F]{1,4}$/i); ele.find('.hex-input').on('keyup',function(e){ var regExp = new RegExp(/[0-9A-F]/i); var last = $(this).val().substr(-1) console.log(last); if(!regExp.test(last)){ console.log("NOPE"); $(this).val($(this).val().slice(0,-1)); } }); $picker = ele.find('.pixel-picker'); $mini = ele.find('input.pixel-mini-colors'); $mini.minicolors({ inline:true, format:'rgb', change: function(value, opacity) { var rgb = $(this).minicolors('rgbObject'); $timeout(function() { // scope.pixels[scope.pixelIndex] = [rgb.r,rgb.g,rgb.b]; scope.rgb = rgb; scope.hexValue = rgb_to_hex(scope.rgb.r,scope.rgb.g,scope.rgb.b); }); } }); $picker.appendTo(document.body); $picker.on('click',function(e){ // e.preventDefault(); e.stopPropagation(); }).on('mousedown',function(){ scope.startedIn=true; }); scope.$close = function(){ $picker.removeClass('open'); scope.pixelIndex = null; scope.rgb = {}; } scope.$set = function(){ $picker.removeClass('open'); scope.pixels[scope.pixelIndex] = [scope.rgb.r,scope.rgb.g,scope.rgb.b]; scope.pixelIndex = null; put_palette(); scope.rgb = {}; } scope.pickMe = function(i,e){ e.preventDefault(); e.stopPropagation(); var p = $(e.target).offset(); var color = scope.pixels[i]; $mini.minicolors('value', "rgb("+color.join(',')+")"); scope.stored = color; scope.pixelIndex = i; scope.hexValue = rgb_to_hex(color[0],color[1],color[2]); $picker.css('top',p.top+'px').css('left',p.left+'px').addClass('open'); } $(document).on('mouseup',function(e){ if(!scope.startedIn){ $picker.removeClass('open'); scope.pixelIndex = null; } scope.startedIn=false; }); scope.$color = function(c){ return { 'background-color': "rgb("+c[0]+","+c[1]+","+c[2]+")" } } function put_palette(){ if(scope.pixels.length>0){ var canvas_copy = document.createElement('canvas'); var ctx_copy = canvas_copy.getContext('2d'); var idata = ctx_copy.getImageData(0,0,16,16); for(var i=0;i{{params.value}}s
    {{params.max+0.1}}s
    ', require: 'ngModel', link: function(scope,ele,attr,ngModelCtl){ scope.params = {value:0}; var $input = $(ele).find('input'); scope.$watch('ngModel',function(nv,ov){ if(nv!=ov){ scope.params.value = nv; } }); scope.$watch('frames',function(nv){ console.log('frame change', nv); if(nv){ scope.params.max = nv; $input.attr('max',nv); } }); $input.on('change',function(e){ console.log('change!'); ngModelCtl.$setViewValue(scope.params.value); ngModelCtl.$render(); }); } } }) app.directive('gifPreview',function(){ return { // template: '
    ', template: '', link: function(scope,ele,attr){ scope.preview_scale = 1; // $(ele).on('resize',function(e){ console.log($(ele).find('.preview-wrap').width()); // var aspect = scope.settings.dimensions.height/scope.settings.dimensions.width; // }); scope.$previewStyle = function(){ return { 'background-image':'url('+scope.thumbnail+')', 'max-width':scope.settings.dimensions.width+'px', 'max-height':scope.settings.dimensions.height+'px' // 'height': (scope.settings.dimensions.height/scope.settings.dimensions.width)*100 + 'vw' }; // console.log($(ele).width()); // if($(ele).width() < scope.settings.dimensions.width || $(ele).height() < scope.settings.dimensions.height){ // return { // 'width':'100%', // 'max-width':scope.settings.dimensions.width+'px', // 'max-height':scope.settings.dimensions.height+'px', // 'padding-bottom': (scope.settings.dimensions.height/scope.settings.dimensions.width)*100 + '%' // } // }else{ // return { // 'max-width':scope.settings.dimensions.width+'px', // 'max-height':scope.settings.dimensions.height+'px', // 'padding-bottom': (scope.settings.dimensions.height/scope.settings.dimensions.width)*100 + '%' // // 'height':scope.settings.dimensions.height+'px' // } // } } } } }) ================================================ FILE: app/tpl/loader.html ================================================ ================================================ FILE: app/tpl/palette.html ================================================
    ================================================ FILE: package.json ================================================ { "name": "gif-tuna", "version": "1.0.7", "description": "A modern cross-platform video to gif converter", "scripts": { "postinstall":"npm --prefix ./app install ./app", "start": "electron ./app/", "build_mac": "electron-packager ./app GifTuna --ignore=.gitignore --platform=darwin --icon=./resources/logo-hires-v2.icns --out=./build/mac/ --overwrite", "build_win": "electron-packager ./app GifTuna --platform=win32 --icon=./resources/logo-hires-v2.iconset --out=./build/win/ --overwrite", "build_linux": "electron-packager ./app GifTuna --platform=linux --icon=./resources/logo-hires-v2-256x256@2x.png --out=./build/linux/ --overwrite", "build_all":"npm run build_mac && npm run build_win && npm run build_linux" }, "author": "brian@ndmweb.com (@dudewheresmycode)", "license": "MIT", "devDependencies": { "electron": "~1.6.2", "electron-packager": "^8.7.1" } }