Coder Social home page Coder Social logo

nathanwalker / angular2-cloudtasks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cloudtasks/angular2-cloudtasks

0.0 3.0 0.0 19 KB

Helps using Cloudtasks.io image processing task by substituting your images sources with the processing URL.

TypeScript 72.63% JavaScript 27.37%

angular2-cloudtasks's Introduction

npm version Build Status Codacy Badge Coverage Status

Github Releases

Allows you to serve highly optimized images to your client apps.

angular-cloudtasks helps using Cloudtasks.io image processing task by substituting your images sources with the processing URL.

With this you can process your images on the fly applying resize, trim, and even filters to your images. In the end you will save a lot of bandwidth for you and your users as well as improve the overall user experience.

You will need a Cloudtasks.io account to be able to use this module;

Installation

First you need to install the npm module:

npm install angular2-cloudtasks --save

If you use SystemJS to load your files, you might have to update your config with this if you don't use defaultJSExtensions: true:

System.config({
	packages: {
		"/angular2-cloudtasks": {"defaultExtension": "js"}
	}
});

Finally, you can use angular2-cloudtasks in your Angular 2 project. It is recommended to instantiate CloudtasksService in the bootstrap of your application and to never add it to the "providers" property of your components, this way you will keep it as a singleton. If you add it to the "providers" property of a component it will instantiate a new instance of the service that won't be initialized.

import {CloudtasksService} from 'angular2-cloudtasks/angular2-cloudtasks';

bootstrap(AppComponent, [
	CloudtasksService
]);


import {Component, View, Injectable} from 'angular2/angular2';
import {CloudtasksService, CloudtasksDirective} from 'angular2-cloudtasks/angular2-cloudtasks';

@Injectable()
@Component({
	selector: 'app'
})
@View({
	template: `<img [ctSrc]="'http://example.com/image.jpg'" [ctOptions]="{trim: true, smart: 'face', filters: 'blur(10):flip()'}">`,
	directives: [CloudtasksDirective]
})
export class AppComponent {
	constructor(cloudtasks: CloudtasksService) {
		// Required: set your cloudtasks.io client id
		cloudtasks.setId('YOUR_CLIENT_ID');

		// Optional: set global options
		cloudtasks.settings.options = {
			trim: false
		}
		// Optional: set global settings
		cloudtasks.settings.placeholderImage = "http://example.com/placeholderImage.jpg";
	}
}

API

CloudtasksService

Settings:

  • clientId: (string) Cloudtasks.io client id
  • dev: (boolean) Set environment to dev (default: false)
  • options: (object) Global options for image processing (Docs)
  • photoWidths: (array) Array of 'Ints' to be used for width approximation calculation
  • photoHeights: (array) Array of 'Ints' to be used for height approximation calculation
  • placeholderImage: (string) Set global placeholder image url to be used while waiting for original image (default: '')

Methods:

  • setId(id: string): Sets the client id
  • getSettings(): Gets the settings

CloudtasksDirective

  • ctSrc: (string) (required) Sets original image url
  • ctOptions: (object) (optional) Sets options for image processing (Docs)
  • ctPlaceholderImage: (string) (optional) Sets placeholder image url to be used while waiting for original image
  • ctSize: (string) (optional) Sets size for image processing (if not set we will try to check the best size automatically)
  • ctForceSize: (boolean) (optional) Forces the exact size for image processing

Example:

<img [ctSrc]="'{{imgUrl}}'" [ctSize]="'800x600'" [ctOptions]="{trim: true, smart: 'face', filters: 'blur(10):flip()'}" [ctPlaceholderImage]="'http://example.com/placeholderImage.jpg'" [ctForceSize]="true">

TODO

  • Find a way to detect parent size (without direct DOM access)

License

(The MIT License)

Copyright (c) 2015 Reality Connect

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.

angular2-cloudtasks's People

Contributors

jonnybgod avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.