Code Monkey home page Code Monkey logo

web-photo-filter's Introduction

Web Photo Filter

Web Photo Filter is a web component to apply Instagram-like WebGL filters to photos.

GitHub release Tweet

Table of contents

Introduction

This component has for goal to make Instagram-like filters for photos accessible for the web.

Image modification solutions and fast processing

Others web based filter solutions often use CSS (for example Instagram.css) or Javascript to modify images.

Applying CSS do not modify the underlying image, and only apply a visual layer to it.

Most Javascript based solutions are not always optimized well enough to be used on mobile devices.

I was looking to create an almost instantaneous filter solution, similar to what Instagram leverages in its mobile application.

Supported by major browsers and devices

As of Feburary 2018, Web Photo Filter utilizes WebGL based technology because it is well supported across modern browsers and mobile devices.

In the future, Web Photo Filter may use WebGL 2 when it will be better supported.

In case WebGL would not be supported on a particular platform, and to avoid producing an error, the component will display the original image without modification.

Lightweight, fast boot time, lazy loading, support across the most popular frontend frameworks

This project is a web component built with the amazing Stencil compiler.

Installation

npm install web-photo-filter

React

You can use a React specific wrapper for this component.

Install it as following:

npm install web-photo-filter-react

Consume it in your code:

import {WebPhotoFilter} from 'web-photo-filter-react/dist';

render() {
    return <WebPhotoFilter/>
}

Usage

The Web Photo Filter Component can be use as following:

<web-photo-filter src="assets/img/test.jpg" filter="sepia"></web-photo-filter>

The only required parameter is the img src tag. It also supports images provided as https if the anonymous crossorigin can be use.

Filter

Filter is an optional parameter. Omitting this attribute or specifying a null value will result in no processing within the component. The source image will be displayed unmodified.

The list of available filters is available in class src/types/web-photo-filter-type.ts. Currently: sepia, blue_monotone, violent_tomato, greyscale, desaturate, brightness, saturation, contrast, hue, cookie, vintage, koda, technicolor, polaroid, bgr.

You can provide a unique filter or, a comma separated list of multiple filters.

filter is a string parameter

Example: Sepia

<web-photo-filter src="assets/img/test.jpg" filter="sepia"></web-photo-filter>

Example: Multiple filters

<web-photo-filter src="assets/img/test.jpg" filter="technicolor, saturation(1.6), contrast"></web-photo-filter>

FilterLoad

If you would like to start or process the result after the component did finish is processing, an event will be triggered containing the resulting image (no filter) or canvas. In addition, it contains also an indication telling you if WebGL is supported or not.

<web-photo-filter onFilterLoad={($event) => imageLoaded($event)} src="imgURI" filter="sepia"></web-photo-filter>

The description of the event is available in the interface src/types/web-photo-filter-result.ts

filterLoad emit an event of type WebPhotoFilterResult

Level

Some filters (brightness, saturation, contrast and hue) are variable. To modify their default values, you could use the variable level.

If multiple filter are provided, it applies to all except if a specific level is provided for a filter, such as for example saturation(1.1).

<web-photo-filter src="assets/img/test.jpg" filter="brightness" level="1.2"></web-photo-filter>

level is a number parameter

Credits

This web component would not had been possible without the brilliant article and WebGL core processing code written by Mike Riethmuller โค๏ธ

The sources of nine filters (Brownie, Brightnes, etc.) were adapted from the project WebGLImageFilter by Dominic Szablewski ๐Ÿ‘

Limitation

WebGL is well supported by most modern browsers, but there may be some use cases where it is not. In the case that WebGL is not supported, there is a fallback scenario implemented in the component.

iOS (WKWebView)

While testing a couple of years ago, I found out that Web Photo Filter works very well on iPhone 6 and above. It is possible to load all filters on the same page without performance issues.

Android (WebView)

Likewise I discovered that these filters do not work very well on Android 7 and above. Testing for Android was ran on a Samsung Edge (Android 7.1), Nexus 5X and Sony (Android 8.1).

The Android Webview seems to handle canvas less actively and it's iPhone counterpart. Therefore I do not recommend using all filters on the same page, but only integrating a few of them at a time, otherwise you'll see a negative performance impact.

Tutorial

Simon Grimm (@saimon24) published a tutorial "Ionic Image Filter Like Instagram Using WebGL Filters" which displays step by step how to create a Ionic app and include this component easily.

Note: to follow this tutorial, version 2 of the component has to be use.

License

MIT ยฉ David Dal Busco

web-photo-filter's People

Contributors

adamdbradley avatar elebetsamer avatar jgw96 avatar kensodemann avatar mlynch avatar peterennis avatar peterpeterparker avatar saimon24 avatar siemato avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

web-photo-filter's Issues

Thumbnail (canvas/image) disappears after interacting with filters

Hi,

I implemented the solution from https://devdactic.com/ionic-photo-filters-instagram/

Filters are being applied fine to the top image, and the filter thumbnails initially work. But sometimes when I click on the filter thumbnails the image of other filters or even the one I clicked disappears - see image below:

web-photo-filter-error

I also see this on Chrome Dev Tools when I click on a filter:

web-photo-filter.entry.js:277 WARNING: Too many active WebGL contexts. Oldest context will be lost.

Ionic:

   Ionic CLI                     : 6.18.1 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 6.0.3
   @angular-devkit/build-angular : 13.0.4
   @angular-devkit/schematics    : 13.0.4
   @angular/cli                  : 13.0.4
   @ionic/angular-toolkit        : 5.0.3

Capacitor:

   Capacitor CLI      : 3.4.0
   @capacitor/android : 3.4.0
   @capacitor/core    : 3.4.0
   @capacitor/ios     : not installed

Utility:

   cordova-res : not installed globally
   native-run  : 1.5.0

System:

   NodeJS : v14.15.1 (/usr/local/bin/node)
   npm    : 8.3.1
   OS     : macOS Monterey

Any idea of what could be causing this and how to fix?

Thanks in advance and thanks for providing us with such useful library!
Caio

Canvas element not showing in app

Hi there,
The canvas element is not visible in the application
What can be the problem ?

I tried it with 1.1.1 and 2.1.1

see the demo video: https://www.youtube.com/watch?v=jfPTBsDSZW0

here is the code:

TS file:

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, ViewController } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-edit-image',
  templateUrl: 'edit-image.html',
})
export class EditImagePage {

  selectedFilter = null;
  image: any;
  level = 1;
  result: HTMLElement;

  constructor(
    public navCtrl: NavController, 
    public navParams: NavParams,
    public viewCtrl: ViewController) {

      //this.image = navParams.data.image;
      this.image = 'assets/imgs/view.jpg';
      this.filter(null, 1);
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad EditImagePage');
  }

  dismiss(){
    this.viewCtrl.dismiss();
  }

  filter(selected, level?){
    this.selectedFilter = selected,
    this.level = level ? level : 1;
  }

  imageLoaded(e){
    console.log('imageLoaded: ', e);
    this.result = e.detail.result;
  }

  saveImage() {
    let canvas = this.result as HTMLCanvasElement;
    let base64 = canvas.toDataURL('image/jpeg', 1.0);
  }

}

HTML file:

<ion-header>
  <ion-navbar>
    <ion-buttons left>
      <button ion-button icon-only (click)="dismiss()">
        <ion-icon name="arrow-back"></ion-icon>
      </button>
    </ion-buttons>  
  
    <ion-title>Edit Image</ion-title>

    <ion-buttons right>
      <button ion-button icon-only (click)="filter(null, 1)">
        <ion-icon name="refresh"></ion-icon>
      </button>
    </ion-buttons>  

  </ion-navbar>
</ion-header>

<ion-content>
  <ion-row *ngIf="image">
    <ion-col>
      <button ion-button outline color="primary" (click)="filter('Sepia')">
        Sepia
      </button>
    </ion-col>
    <ion-col>
      <button ion-button outline color="primary" (click)="filter('Polaroid')">
        Polaroid
      </button>
    </ion-col>
    <ion-col>
      <button ion-button outline (click)="filter('greyscale')">
        Grey
      </button>
    </ion-col>
    <ion-col>
      <button ion-button outline (click)="filter('contrast')">
        Contrast
      </button>
    </ion-col>
    <ion-col>
      <button ion-button outline (click)="filter('brightness', 1.7)">
        Bright
      </button>
    </ion-col>
    <ion-col>
      <button ion-button outline (click)="filter('saturation')">
        Saturation
      </button>
    </ion-col>
    <ion-col>
      <button ion-button outline (click)="filter('hue', 120)">
        Hue
      </button>
    </ion-col>
  </ion-row>

  selectedFilter: {{selectedFilter}}
  <br>
  level: {{level}}
  
  <web-photo-filter 
    [class.only-original]="!selectedFilter" 
    [class.no-original]="selectedFilter" 
    [src]="image"
    [filter]="selectedFilter" 
    [level]="level" 
    keep="true" 
    (filterLoad)="imageLoaded($event)">
  </web-photo-filter>
 
</ion-content>
  

CSS file:

page-edit-image {
    canvas {
        width: 100%;
      }
    .no-original img.display-no-filter {
        display: none !important;
    }
    .only-original canvas {
        display: none !important;
    }
}

image

Large weight image not working

Hi there,
I am trying to do a filter on a large weight image and the filters are not showing and not working.

I take an image from the local device library that weight 8 MB and none of the filters show and work.

20190613_005729

Is it possible to combine multiple filters into one?

[x] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://stencil-worldwide.slack.com

I like how this component looks thus far, the only thing I am confused about is it's ability to combine multiple filters into one.

For example, currently, I am serving filters via CSS, which apply at load-time. One of my filters looks like this:

{name: 'Aden', class: 'aden', filter: 'contrast(0.9) brightness(1.2) saturate(0.85) hue-rotate(20deg)'},

I noticed that all of the examples that you provide, only allow you to filter based on one value (Hue, brightness, saturation, etc...). So I was curious what goes into creating custom filters, like the one above.

I checked out the web-photo-filter-type.tsx but I am not sure how to utilize this class to accomplish what I am trying to do, right now. Can you give any insight on the steps required to create a new filter?

Typos on website

Couldn't find a repo for the website itself, so I'm submitting it here:

image

image

Multiple filters on scrollable div not showing

Hi,

I am having a problem with a scrollable div.
On the scrollable div I want to show buttons and in the button there is a web-photo-filter component.
But I can't see all the filters.
What can be the problem ?

I am working with IONIC 3
and web-photo-filter version: 1.1.1

ezgif com-video-to-gif

This is my code:

HTML code:

<div class="page-slides">
    <div class="my-slide">
      <button ion-button clear (click)="filter('sepia')">
        <web-photo-filter [src]="image" filter="sepia"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('blue_monotone')">
        <web-photo-filter [src]="image" filter="blue_monotone"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('violent_tomato')">
        <web-photo-filter [src]="image" filter="violent_tomato"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('greyscale')">
        <web-photo-filter [src]="image" filter="greyscale"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('brightness', 1.2)">
        <web-photo-filter [src]="image" filter="brightness" level="1.2"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('saturation')">
        <web-photo-filter [src]="image" filter="saturation"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('contrast')">
        <web-photo-filter [src]="image" filter="contrast"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('hue', 120)">
        <web-photo-filter [src]="image" filter="hue" level="120"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('cookie')">
        <web-photo-filter [src]="image" filter="cookie"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('vintage')">
        <web-photo-filter [src]="image" filter="vintage"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('koda')">
        <web-photo-filter [src]="image" filter="koda"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('technicolor')">
        <web-photo-filter [src]="image" filter="technicolor"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('polaroid')">
        <web-photo-filter [src]="image" filter="polaroid"></web-photo-filter>
      </button>      
    </div>
    <div class="my-slide">
      <button ion-button clear (click)="filter('bgr')">
        <web-photo-filter [src]="image" filter="bgr"></web-photo-filter>
      </button>      
    </div>
  </div>

when i use web-kit-filter where can i found the filtered image

I am using ionic3 and i followed the process that u described,but where can i found the filtered image.As i want to display the filtered image
My ts will look like this
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Camera, CameraOptions } from '@ionic-native/camera';
import { ImagePicker } from '@ionic-native/image-picker';
import { Crop } from '@ionic-native/crop';
import 'web-photo-filter';

/**

@IonicPage()
@component({
selector: 'page-edit',
templateUrl: 'edit.html',
})
export class EditPage {
newPhoto:any;
photonew:any;
filter:string='null';
constructor(public navCtrl: NavController, public navParams: NavParams,
private camera:Camera,
private imagePicker:ImagePicker,
private crop: Crop) {
}

ionViewDidLoad() {
console.log('ionViewDidLoad EditPage');
}

pickPhoto(){
const options: CameraOptions = {
quality: 70,
destinationType: this.camera.DestinationType.DATA_URL,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
saveToPhotoAlbum:true,
allowEdit:true
}
this.imagePicker.getPictures(options).then((results) => {
for (var i = 0; i < results.length; i++) {
console.log('Image URI: ' + results[i]);
}
this.newPhoto=results[0];
}, (err) => { });
}

cropPhoto(pic){
this.crop.crop(pic, {quality: 75})
.then(
newImage => {
console.log('new image path is: ' + newImage);
this.photonew=newImage;
},
error => console.error('Error cropping image', error)
);
}
effectOne(){
console.log(this.newPhoto);
console.log("one");
this.filter="sepia";
}effectTwo(){
console.log(this.newPhoto);
console.log("two");
this.filter="blue_monotone";
}effectThree(){
console.log(this.newPhoto);
console.log("three");
this.filter="violen_tomato";
}
}

My html file is

capture

If u respond as soon as possible it will be helpful,thanks

version ^2.0.0 no display angular 5 and ionic-angular 3.9.2

The filters for version ^2.0.0 are not displayed in an Ionic 3 app. Is it supposed to be compatible?
Angular 5 and ionic-angular 3.9.2

Filters used as follows:
<web-photo-filter [src]='somebase64Image' (click)="applyFilter('')" [filter]='filterStringEgSepia' (filterLoad)="filterLoaded($event)"> </web-photo-filter>

I just can't get this library work :(

Hey man. First, I really appreciate you taking the time to make this library. I am very interested in having image photo filter functionality of the type you describe and demonstrate on the home page for this library.

The problem is, I just can't get it to work! I've tried everything I can think of.

So I've created a very small test project that I'm hoping you could look at, and let me know what I'm doing wrong:
https://github.com/varunj166/web-photo-filter-testing

All it contains is the react WebPhotoFilter component (which doesn't seem to work), as well as the actual web-photo-filter web component (which was a last ditch effort to get something to show up on the page).

PLEASE take a moment and let me know what's wrong. I'm sure it's something simple.

Thanks!

web-photo-filter tag is not rendering on iOS 15 device Ionic 6

Platform iOS
Ionic 6 Capacitor Angular 11

After running ionic cap sync. When app is run on Xcode > Device it does not show web-photo-filter tag. Only show img tag.

photoToFilter.thumbnail is base64 image stored in local storage.

PROBLEM: E/Capacitor: Unable to open asset URL: http://localhost/webphotofilter.js

app/index.html
<script async src="webphotofilter.js"></script>

angular.json

`{
                "glob": "webphotofilter.js",
                "input": "node_modules/web-photo-filter/dist",
                "output": "./"
              },
              {
                "glob": "webphotofilter/*",
                "input": "node_modules/web-photo-filter/dist",
                "output": "./"
              }`

app/main.ts

`import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

import { defineCustomElements } from "@ionic/pwa-elements/loader";

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule)
  .catch(err => console.log(err));

//Call the elemnt loader after the platform has been bootstrapped
defineCustomElements(window);`

imagefiltering.module.ts

`import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';

import { IonicModule } from '@ionic/angular';

import { ImagefilteringPageRoutingModule } from './imagefiltering-routing.module';

import { ImagefilteringPage } from './imagefiltering.page';
import { SwiperModule } from 'swiper/angular';

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    SwiperModule,
    ImagefilteringPageRoutingModule
  ],
  declarations: [ImagefilteringPage],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class ImagefilteringPageModule {}
`

imagefiltering.page.ts

`import { Component, OnInit } from '@angular/core';
import { Storage } from '@capacitor/storage';

@Component({
  selector: 'app-imagefiltering',
  templateUrl: './imagefiltering.page.html',
  styleUrls: ['./imagefiltering.page.scss'],
})
export class ImagefilteringPage implements OnInit {

  product:any;
  photoTofilter:any = {
    thumbnail: ""
  };

  constructor() { }

  ngOnInit() {
  }

  ionViewDidEnter(){
    Storage.get({key: 'product'}).then((result:any)=>{
      if(result && result.value)
      {
         this.product = JSON.parse(result.value);
      }
    });
    Storage.get({key: 'editImage'}).then((result:any)=>{
      if(result && result.value)
      {
         this.photoTofilter = JSON.parse(result.value);
      }
    });
  }

}
`

imagefiltering.page.html

`<ion-header>
  <ion-toolbar mode="ios">
    <ion-buttons slot="start">
      <ion-back-button text="" icon="chevron-back" defaultHref="/selection/device" color="medium"></ion-back-button>
    </ion-buttons>
    <ion-title>Apply Filter</ion-title>
  </ion-toolbar>
</ion-header>

<ion-content>
  <ion-grid>
    <ion-row>
      <ion-col>
        <img [src]="photoTofilter.thumbnail"/>
        <web-photo-filter [src]="photoTofilter.thumbnail" filter="sepia"></web-photo-filter>
      </ion-col>
    </ion-row>
  </ion-grid>
</ion-content>

<ion-footer>
  <swiper [spaceBetween]="10" [slidesPerView]="'auto'" [centeredSlides]="true" [loop]="true">
    <ng-template swiperSlide>
      <img [src]="photoTofilter.thumbnail"/>
    </ng-template>
    <ng-template swiperSlide>
      <web-photo-filter [src]="photoTofilter.thumbnail" filter="sepia"></web-photo-filter>
    </ng-template>
  </swiper>
</ion-footer>
`

bug

I can't seem to use it

image

WebPhotoFilter is undefined

I saw

image

Empty file

Using An Image From Https

Is there any way to use an image from an https path if we are in control of where that image is stored? For example, if we have it stored on Azure Storage or on our own server?

I think why it is not allowed is because of CORS. If that is true, the error I get when I try to do this with web-photo-filter is usually solved by setting crossorigin on the img tag.

Is there a way to set the crossorigin attribute on the image element to possibly allow for using images from an https origin?

Has anyone found out any way to use an https image src?

Install on Ionic 3

Hi,
What is the way to install this component on an Ionic 3 project?

Thank you

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.