Are photoshop like blend modes possible with html5 and draggable images - javascript

I'm using some javascript to make my images draggable
I want to be able to move my images over each other and create a similar effect to the multiply blending mode in photoshop.
I've seen how this is possible with static images, but I want these to change as they are moved around the screen, rather than just loading up with the effect already applied.
Is this possible within the canvas? Is there a better way?

Yes, it is possibile with Canvas and processing.js, but you will not be able to use your actual draggable plugin (it doesn't seem HTML5).
Read this http://processingjs.org/reference/blend_/ but remember Blending on Canvas could be very slow (it depends by images' resolution and by Browser' engine).

Related

How can I optimize HTML canvas and JavaScript to handle large sized images for a web-based image editor

I am building a web-based image editor, and everything seems to work fine until very large images are uploaded (>5mb), and then operations like adjusting the brightness using a slider takes a while to reflect. The issue is quite obvious, and that is because I have to loop through each pixel (step of 4) in context.getImageData().data in order to modify each pixel value.
I checked out a couple of already existing online image editors, and theirs seem to work pretty well without lags.
Initially, my first step was to resize the image to fit the canvas on the screen which worked fine without lags, but why I switched to modifying the original image size was because the original size does not change compared to the one on the screen which changes if the user resizes the screen (or if chrome displays the currently downloading bar at the bottom of the browser), and since it is constant, I can always keep track of all editing operations, and then display on the screen by basing scaling down to fit the screen.
I'd love to know how I can optimize for large-sized images, without losing the quality of the original (due to resizing etc). Thanks!
[UPDATED]
This was copied from a comment under this post.
"JavaScript is not suited for image pixels editing. That is what the GPU is for. Most image manipulation needs can be done using filters, standard 2D canvas as they use the hardware designed for the task. If you have custom PX manipulation needs then WebGL is the solution."

What HTML5 Canvas Pixel Detection and image manipulation libraries are out there?

I am trying to develop a "Web App" (for lack of better terminology) that displays a sort of interactive map using the HTML5 Canvas element for mobile devices. The map has about 30 buildings (made from semi-transparent PNG images on it) of different shapes and sizes. I want the user to be able to tap on any of the buildings to get information about them. The buildings are often within the same theoretical bounding box of others, so it isn't as simple as just detecting when the user taps in a bounding box (imagine a U shaped building with another building inside the U). Therefore, it should use some sort of raster pixel detection. To make matters more complicated, I need to allow the user to zoom in/out and pan around on the map (because 30 buildings and a map are way too much to show a user on a tiny cellphone screen). So scaling and moving smoothly is a necessity.
I am looking for a JavaScript library that can support these functions:
Image pixel detection
Mobile touch events
Canvas (or stage?) scaling
Usable on mobile devices
So far, I have found KineticJS which supports all of these features. But when I try to move the map with more than 4 buildings on the stage, it is way too jumpy. I tried checking into Fabric.js but it doesn't seem to have pixel detection (as it selects the image when you click within the bounding box, not the actual image itself).
Is there any other JavaScript library out there that can do these things?
Thanks for any help!
The KineticJS is pretty good ( the best lib i found so far )
I never tried to use png images with it, but zooming and panning with a few hundreds primitive objects is pretty smooth (without pixel detection - I imagine the pixel detection is quite cpu expensive operation ).
Maybe you could try overlay standard polygons ( a few for one building ) and attach to the same click/tap event.
Also you don't necessary need to move objects on the canvas you can just put bigger canvas in smaller div ( with overflow:hidden) and drag the whole canvas element.

HTML5 <canvas> scaling to different detected screen sizes

I'm making a simple app using the HTML5 <canvas> tag and compile the code into a native app using Cordova, but the issue is that canvas use coordinates that are not relative to the size of it, and we plan to have it across Apple and Google supported devices...which could mean at least more than 10 screen sizes/resolutions.
So I want to know how to work with a <canvas> (which will be in fullscreen) on different screen sizes.
Will using model-based coordinates help?
Thanks!
I'm pretty sure you can only set one width and height in the canvas element itself. If you want to change its size depending on portrait, landscape, etc., you could use CSS media queries. I'm pretty sure that's going to make your canvas not look very high quality in certain situations, since you're essentially just blowing up or shrinking the size of a predefined element.
There might be a fancier way to redraw the canvas depending on screensize, etc., but I haven't tried it.

Rotate image clockwise or anticlockwise inside a div using javascript

HI, Is there a way by which I can rotate an image inside a div clockwise or anticlockwise.
I have a main fixed width div[overflow set to hidden] with images loaded from database. There is a scroll bar for showing the images inside the div. When image is clicked then I need to show the rotating animation either in clockwise or anticlockwise direction.
I have done it using Matrix filter. I would like to know whether it is possible to be done in IE only without using any filters.
try this: http://raphaeljs.com/image-rotation.html
uses canvas but also supports IE
If you're using jQuery, jQueryRotate is a small (less than 3Kb minified+gzipped) plugin that rotates images:
http://jqueryrotate.com/
The only way I can think of for rotating images on the client-side in IE is using filters. For somewhat recent versions the other browsers you can use the <canvas> control.
Your alternative is to use a server-side script to rotate the image. Then you can send the information on how to rotate it with JavaScript (i.e. generate a path to the image such as /rotate?image=img.jpg&amount=90)
CSS3 supports rotation, but it isn't widely supported.
As you asked for JavaScript solution, here's one, but I don't think you can get smooth images.
There is other way to rotate images without any filters / html5.. it's nasty and useless in real world, but possible.
You can store your image as array of pixels, for javascript. Write function to perform rotation with it and encode it to base64 datauri, bmp could be easy and replace image.src with it.
There will be some limitation about filesize and support in old browser and of course terrible performance..

Web: solution for image rotate and zoom

I have a web page which displays a large image, for example a page from a magazine. I have no control over the image size or orientation. It's possible that the image may need to be rotated by the user to orient it correctly.
Are there any Javascript or Flash solutions that will allow someone to rotate and zoom a given image? Ideally I'd specify a single image and the dimensions to use when displaying it. If the image is larger than those dimensions, the user could zoom in and view a portion of the image in greater detail.
I've seen a couple of solutions for rotating images with straight Javascript and CSS. Raphael would do the trick. There is apparently even an example featuring rotating an image. (it uses SVG but is support on all major browsers)
This one is not cross browser, but is an interesting exercise nevertheless.
As for flash rotation etc...
For rotating images, I used jquery-rotate and it works very well.
It is not totally cross-browser, it doesn't work with IE6 (and probably other old browsers).
For zooming, I guess you could make your own implementation using javascript, you can just resize the image (easy with jQuery).

Categories

Resources