import { Filter } from '../types/filter.type' ; import { normalizeNumberPercentage } from '../utils/filter.utils' ; export const opacity = ( context , amount = '1' ) => { amount = normalizeNumberPercentage ( amount ) ; if ( amount < 0 ) { return context ; } if ( amount > 1 ) { amount = 1 ; } const { height , width } = context . canvas ; const imageData = context . getImageData ( 0 , 0 , width , height ) ; const { data } = imageData ; const { length } = data ; for ( let i = 3 ; i < length ; i += 4 ) { data [ i ] *= amount ; } context . putImageData ( imageData , 0 , 0 ) ; return context ; } ;