Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:25:51+00:00 2026-06-04T21:25:51+00:00

I need to allow user to pick images and then save the base64 image

  • 0

I need to allow user to pick images and then save the base64 image data to web sql database in Chrome. Then at one point when user gets online, upload those data to server.

I can get the image data like this:

function onFileUploadChange(input) {
        if (input.files && input.files[0]) {
            //alert(input.files.length);
            for (i = 0; i < input.files.length; i++) {
                previewImage(input.files[i], "ImageTag" + getUniqueID());
            }
        }
    }

    function previewImage(file, imgID) {

        $("#ImagePreview").append("<img id='" + imgID + "'  />");

        var reader = new FileReader();
        reader.onload = function (e) {
            $("#" + imgID)
            .attr('src', e.target.result)
            .width(200)
            .height(200);

        };

        reader.readAsDataURL(file);
    }

the image.src has the base64 image data.

Once user clicks save, I will grab all images’ src which is the base64 image data and save them to web sql database of chrome.
Now the problem is most pictures are too large. I want to resize them to say 1/4 of original size, then save it to web sql. Is there any way to do it? Probably with canvas?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:25:54+00:00Added an answer on June 4, 2026 at 9:25 pm

    Here’s an example of doing it in canvas:

    http://jsfiddle.net/7QMqX/

    In case jsfiddle goes down, here’s the relevant part:

    img.onload = function() {
        // original image size:
        console.log(img.width); // 182
        console.log(img.height); // 176
        // lets resize it to 1/4 original size
        var bigside = Math.max(img.width, img.height);
        var ratio =  0.25;
        can.width = img.width * ratio;
        can.height = img.height* ratio;
        ctx.scale(ratio, ratio); // scale by 1/4
        ctx.drawImage(img, 0, 0);
        // Lets also show the original image for comparison:
        document.body.appendChild(img);
    
        // anyway, now we can use this command to get the base64 data of the resized image:
        console.log(can.toDataURL());
    }
    

    You can draw anything to canvas, and so you load the image, resize the canvas to be 1/4 the image’s size, scale the canvas by 1/4, and then draw the image. Then you can get the bitmap on the canvas by calling toDataURL, which returns the base64 string.

    note that toDataURL will fail if any of the items drawn to a canvas are not same-domain or cors-enabled.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a web application that need to allow the user to drag
I need to allow a user to process some data. Data is say 100
Through the website, I need to allow the user to add attachments and store
Is there a winforms month-only picker control? I need to allow the user to
I need a regex that allow user to insert a password in a field.
I need to allow a consultant to connect to SSIS on a SQL Server
I am creating an iOS user interface to allow a user to pick a
I need to allow the user to rotate a control (the control inherits from
I am using a standard date picker to allow the user to pick a
I have the need to allow a user to tab through making edits on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.