Is it possible whether with JS or jQuery to take an image, make it fit a container proportionally if it's too big for the container, then export the results to a PNG image, saving the step of redoing the image from scratch in a smaller image size ?
Siberian 13
Junior Poster
Recommended Answers
Jump to PostYou could create/resize it on an HTML canvas and export the canvas to PNG using
canvas.toDataURL("image/png")
.
Jump to PostA little more than that. The image has to be resized and drawn onto the canvas, then you can export the canvas to a data url with that function.
Perhaps these links will help:
Jump to PostIf I use
var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d'); var imageObj = new Image(); imageObj.src = 'img url snipped'; imageObj.onload = function() { var width = 200; var height = imageObj.height * (width/imageObj.width); canvas.width=width; canvas.height=height; context.drawImage(imageObj, 0, 0, width, height); };
And remove the …
All 10 Replies
Traevel 216
Light Poster
Siberian 13
Junior Poster
Traevel 216
Light Poster
Siberian 13
Junior Poster
Traevel 216
Light Poster
Siberian 13
Junior Poster
rtrethewey 24
Junior Poster
Traevel 216
Light Poster
Siberian 13
Junior Poster
Traevel 216
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.