html5 - Crop image to canvas -
i have 2 divs
<div id="image-orig"> <img src="image_example.jpg"/> </div> <div id="image-crop"> <canvas id="preview" style="width:548px;height:387px"></canvas> </div>
image_example.jpg can image size.
function updatepreview(c) { if(parseint(c.w) > 0) { var orig = $("#image-orig img")[0]; var canvas = $("#image-crop canvas")[0]; var context = canvas.getcontext("2d"); context.drawimage(orig, c.x*coeff,c.y*coeff,c.w*coeff,c.h*coeff, 0,0,canvas.width,canvas.height ); } } $(function(){ $('#image-orig img').jcrop({ onselect: updatepreview, onchange: updatepreview, aspectratio : parsefloat($('#image-orig img').width()/$('#image-orig img').height()) }); });
coeff - it's coefficient if size image larger div preview.
that's problem: http://dbwap.ru/3725988.png
in second div (canvas). quality image low.
solution found
canvas.width = c.w*coeff; canvas.height = c.h*coeff; context.drawimage(orig, c.x*coeff,c.y*coeff,c.w*coeff,c.h*coeff, 0,0,c.w*coeff,c.h*coeff ); $(that.el).find("#imagecode").attr('src', canvas.todataurl()); $(that.el).find("#imagecode").show();
i'm creating image tag , copying canvas image.
if have access .net, can modify way new images saved jcrop: http://mironabramson.com/blog/post/2009/04/cropping-image-using-jquery,-jcrop-and-aspnet.aspx
solution available without using server-side (.net / php):
first, make sure when use jcrop have html5 canvas image smoothing enabled:
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html
if set, or has no effect, think other options investigate image option available through each browser:
enable smoothing in mozilla - see article example (look 'mozimagesmoothingenabled'):https://developer.mozilla.org/en/canvas_tutorial/using_images#controlling_image_scaling_behavior
apply filters in ie: http://code.flickr.com/blog/2008/11/12/on-ui-quality-the-little-things-client-side-image-resizing/
note: there may sort of flash solution work difficult combine flash solution jcrop , html5 canvas.
Comments
Post a Comment