First load Jquery :
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
Grab the SOURCE then load imgfx.js:
<script type="text/javascript" src="path-to-js/imgfx.min.js"></script>
To apply an effect to an image by id , class or tag or a just target <img/> element with the usual Jquery way:
<script type="text/javascript">
$("img").imgfx({parameters});///will apply to all images on the page
$(".a-class").imgfx({parameters});//will apply to all images with same class
$(".#an-id").imgfx({parameters});//will apply to image targetted by id
</script>
Some of the FX will not work on images that are not on the same server due to the same origin policy.
By the way it works when the remote server send the adequat CORS hearders.
By default the plug-in sets the .crossOrigin attribute of images to "Anonymous".
img.crossOrigin = "Anonymous";
You can read more about this issue here : https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image .
The plug-in have a lot off parameters that allow you to play with.
Some are common to different effects:
mode:"tv"
This parameters allow you to choose the fx you want to use
blendMode: "difference",
You can choose between all of this values:
normal | multiply | screen | overlay | darken |
lighten | color-dodge | color-burn | hard-light |
soft-light | difference | exclusion | hue | saturation |
color | luminosity |clear | copy | destination | source-over |
destination-over | source-in | destination-in |
source-out | destination-out | source-atop |
destination-atop | xor | lighter
This parameters controls the CanvasRenderingContext2D.globalCompositeOperation property for the FX that uses it.
"tv","glitch","zoom","bumpingrect" and "randomsquares" makes use of it.
I think it's fun to play with.
canvassize:2,
This parameter control the size of the canvas by dividing the original image size.
set it to 1 if you want to keep your original image size (and burn your visitor's CPU)
canvassize:"Anonymous",
Can be usefull for CORS settings.
For information the demo image is hosted on instagram and yes it's my cat.
The link to the imagehttps://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/e15/1962897_1082146021812843_1655689444_n.jpg
//TV SIMULATOR SPECIFIC CONTROLS
Themecolor: "#0f0",///DOMINANT COLOR
noise: true,//ENNABLE NOISE LAYER
grainsize: 1,//NOISE GRAIN SIZE
desyncspeed: 5,//SYNC DISPLACEMENT SPEED
syncup: true,//TRUE IMAGE MOVE UP FALSE IMAGE MOVE DOWN
scanspacing: 22,//SPACE BETWEEN SCANLINES
scanheight: 4,//SIZE OF SCANLINES
scanspeed: 1,//SCANLINE DISPLACEMENT SPEED DEFAULT MOVE DOWN, NEGATIVE INT MOVE UP
flickerseed: 10,//FLICKERING: LESS THE NUMBER MORE IT FLICKERS
latunsync: 0,//DISPLACE IMAGE RANDOMLY ON X AXIS
sidenoise: "left", // DRAW LATERAL NOISE LAYER options:"left","right","both","none"
sidenoiseforce: 8,//MAX FORCE OF SIDENOISE
$('#tv').imgfx({
mode:"tv",
Themecolor:"#0f0",
desyncspeed: 1,
scanspeed: 3,
syncup: false
});
//LATERAL GLITCH SPECIFIC CONTROLS
glichforce: 80,
glitchclear: true,
glitchdisplayimage: true,
$('#tv').imgfx({
mode:"glitch"
});
//BASE64GLITCH SPECIFIC CONTROLS
base64glitchforce:0,//BASE64 DESTROY It's an array index : The array is set like this ["64","128","256","1024","2048"]
base64glitchInterval:300,//
$('#base64').imgfx({
mode:"base64",
base64glitchforce:0,
base64glitchInterval:60
});
///ZOOM SPECIFIC CONTROLS
zoomRotationSpeed:1, //rotation speed
zoomSpeed:0.05, // zooming speed
zoomMinScale:0.001,//min scale
zoomMaxScale:15,//max scale
zoomXframe:30,// clear canvas n number of frame
$('#zoom').imgfx({
mode:"zoom",
blendMode:"darken",
zoomRotationSpeed:3,
zoomSpeed:0.005,
zoomMinScale:0.0001,
zoomMaxScale:15,
zoomXframe:5
});
//ROTOZOOM SPECIFIC CONTROLS
rotozoomSpeed:0.01,//ZOOMING SPEED
rotozoomRotateSpeed:0.2,//ROTATION SPEED [use max as 0.9999...]
rotozoomMaxScale:5,//MAX ZOOM
rotozoomMinScale:0.001,//MAX DE-ZOOM
$('#rotozoom').imgfx({
mode:"rotozoom",
rotozoomSpeed:0.01,
rotozoomRotateSpeed:0.2,
rotozoomMaxScale:5,
rotozoomMinScale:0.001
});
//BUMPING RECT SPECIFIC CONTROLS
//THIS FX USE THE blendMode PARAMETER
rectNum: 4,//HOW MANY BOUNCING SQUARES
rectSquare: false,//SQUARES OR RECTANGLES
rectSpeed: 6,//DISPLACEMENT SPEED
rectClear: true,//CLEAR SCREEN EVERY FRAME?
$('#bumpingrect').imgfx({
mode:"bumpingrect",
bledMode:"difference",
rectNum: 4,
rectSquare: false,
rectSpeed: 6,
rectClear: true
});
//KALEIDOSCOPE SPECIFIC CONTROLS
thetaAngle:360,
thetaDiv:30,
$('#kaleidoscope').imgfx({
mode:"kaleidoscope",
thetaAngle:360,
thetaDiv:30,
});
//PIXELLATE SPECIFIC CONTROLS
pixelsize: 100,//MAX SIZE
squared: true,//SQUARED PIXELS pixel width = pixel height
smooth: false,//ENNABLE SOOTHING
$('#pixelate').imgfx({
mode:"pixelate",
pixelsize: 100,
squared: true,
smooth: false
});
//RANDOMRECT SPECIFIC CONTROLS
rdmMaxRect:20,///MAX NUMBER OF RECTANGLES
rdmClearBeforeDraw:true///clear canvas every frame
$('#randomrect').imgfx({
mode:"randomrect",
rdmMaxRect:20,
rdmClearBeforeDraw:false
});
mode: "tv",//DIFFERENT MODES : "tv","glitch","zoom","rotozoom","pixelate","kaleid","bumpingrect","crazyrect",
canvassize:2,//DEVIDE SIZE TO IMPROVE CANVAS PERFORMANCES The more you reduce the size the more you gain perf but you get bigger pixels
blendMode: "difference",//DEFINE A globalCompositeOperation BLEND MODE FOR FX THAT USE IT
crossOrigin:"Anonymous", //Define CORS param
//TV SIMULATOR SPECIFIC CONTROLS
noise: true,//ENNABLE NOISE LAYER
grainsize: 1,//NOISE GRAIN SIZE
desyncspeed: 5,//SYNC DISPLACEMENT SPEED
syncup: true,//TRUE IMAGE MOVE UP FALSE IMAGE MOVE DOWN
scanspacing: 22,//SPACE BETWEEN SCANLINES
scanheight: 4,//SIZE OF SCANLINES
scanspeed: 1,//SCANLINE DISPLACEMENT SPEED DEFAULT MOVE DOWN, NEGATIVE INT MOVE UP
flickerseed: 10,//FLICKERING LESS THE NUMBER MORE IT FLICKERS
latunsync: 0,//DISPLACE IMAGE RANDOMLY ON X AXIS
sidenoise: "left", // DRAW LATERAL NOISE LAYER options:"left","right","both","none"
sidenoiseforce: 8,//MAX FORCE OF SIDENOISE
Themecolor: "#f00",//DEFINE A COLOR OF TV
//BASE64GLITCH SPECIFIC CONTROLS
base64glitchforce:0,//BASE64 DESTROY
base64glitchInterval:300,//
//LATERAL GLITCH SPECIFIC CONTROLS
glichforce: 80,
glitchclear: true,
glitchdisplayimage: true,
//PIXELLATE SPECIFIC CONTROLS
pixelsize: 100,//MAX SIZE
squared: true,//SQUARED PIXELS pixel width = pixel height
smooth: false,//ENNABLE SOOTHING
//BOUNCING RECT SPECIFIC CONTROLS
//THIS FX USE THE blendMode PARAMETER
rectNum: 4,//HOW MANY BOUNCING SQUARES
rectSquare: false,//SQUARES OR RECTANGLES
rectSpeed: 6,//DISPLACEMENT SPEED
rectClear: true,//CLEAR SCREEN EVERY FRAME?
///ZOOM SPECIFIC CONTROLS
zoomRotationSpeed:1,
zoomSpeed:0.05,
zoomMinScale:0.001,
zoomMaxScale:15,
zoomXframe:30,
//ROTOZOOM SPECIFIC CONTROLS
rotozoomSpeed:0.01,//ZOOMING SPEED
rotozoomRotateSpeed:0.2,//ROTATION SPEED [use max as 0.9999...]
rotozoomMaxScale:5,//MAX ZOOM
rotozoomMinScale:0.001,//MAX DE-ZOOM
//KALEIDOSCOPE SPECIFIC CONTROLS
thetaAngle:360,
thetaDiv:30,
//RANDOMRECT SPECIFIC CONTROLS
rdmMaxRect:20,///MAX NUMBER OF RECTANGLES
rdmClearBeforeDraw:true///clear canvas every frame
This plug-in have some isues, and if you know well JQuery and would kindly like to help, this are the thing that i want to fix.
When you instantiate the plug-in a window.requestAnimationFrame or setInteval loop is triggered. If you remove the dynamicly generated canvas element from the DOM, those process are still running in background. I would like to add a .destroy() function that kill everything from an instance of the plug-in but don't know how to do that.
I know it's not really clear but if you ennable the javascript console (firebug or chrome dev tool) and trigger the TV simulator , I left a console log in the window.requestAnimationFrame that logs "im here". If you click Re-print image the loop is still running and still eating CPU. Question is how to kill this? (I know clearInterval() and cancelAnimationFrame() but dont know how to trigger it when output canvas is removed). Please have a look at the source.
Every link to usefull documentation, or advice from clever coder can be helpfull !
Feel free to contact me via github, or my website.