html - Image Reading from base64 data in javascript produces image of different size -
i trying screenshot of page using chrome extension , trying crop image. upon taking screenshot, base64 dataurl of image.
when try render image using dataurl, image renders larger(appears zoomed in) original image. when manually give <img>
object original size renders fine. when draw image canvas, canvas takes enlarged size.
i have been banging head against wall solution problem no avail. appreciated.
//here js code: var image = document.getelementbyid("image"); var canvas = document.getelementbyid('mycanvas'); var context = canvas.getcontext('2d'); image.onload = function() { var sourcex = 0; var sourcey = 0; var sourcewidth = 150; var sourceheight = 80; var destwidth = sourcewidth; var destheight = sourceheight; var destx = 0; var desty = 0; context.drawimage(image, sourcex, sourcey, sourcewidth, sourceheight, destx, desty, destwidth, destheight); };
and here html code, removing dataurl takes space, , pasting url.
<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>js bin</title> </head> <body> <img height = "678" width = "1280" id = "image" src = "http://s12.postimg.org/7r9q3h2vx/ss2.jpg"/> <canvas id="mycanvas" width="500" height="200"></canvas> </body> </html>
the following image(from dataurl) want crop:
the following cropped image get. not intended image because appears enlarged(zoomed in). top left section of original image.
for further reference, here jsbin link: https://jsbin.com/pomayowara/edit?output
the base64 dataurl provided has information image of 2560 × 1356, rescaling image 1280x678. code obtaining original size of image , therefore being enlarged. need send canvas original ratio of image , not resized dimensions of image.
Comments
Post a Comment