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 7887855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:41:19+00:00 2026-06-03T05:41:19+00:00

I have the following fonction, that gets an image as parameter: function getIcon(img){ var

  • 0

I have the following fonction, that gets an image as parameter:

function getIcon(img){
  var canvas = document.createElement("canvas");
  canvas.width = img.width;
  canvas.height = img.height;
  var ctx = canvas.getContext("2d");
  ctx.drawImage(img, 0, 0);
  var dataURL = canvas.toDataURL("image/png");
  return dataURL;
}

for instance:

icon = getIcon(document.getElementById("car_marker"));    

with:

<img id="car_marker" src="img/car.png"/>

Then the icon created is used as a marker in Google Map:

var marker = new google.maps.Marker({ position: latLng,
                                          map: map,
                                          title: description,
                                          id: id,
                                          icon: icon
                                       });

This part is working fine but I now need to modify the getIcon method so it takes another image as parameter and merge both images. As the new image I need to add is in base 64 encoding, the following does not work as expected:

function getIcon(img1, img2){
  var canvas = document.createElement("canvas");
  canvas.width = img1.width;
  canvas.height = img1.height;
  var ctx = canvas.getContext("2d");
  ctx.drawImage(img1, 0, 0);
  ctx.drawImage(img2, 0, 0); // add the base 64 encoded image here... does not work
  var dataURL = canvas.toDataURL("image/png");
  return dataURL;
}

I end up with:

Could not convert JavaScript argument arg 0 [nsIDOMCanvasRenderingContext2D.drawImage]
  • 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-03T05:41:20+00:00Added an answer on June 3, 2026 at 5:41 am

    I finally figured it out:

    // Get the image that will be used as the background image
    image1 = document.getElementById("blank_marker");
    
    // Build image from base64 encoding (image that will be put on the previous one)
    image2 = new Image();
    image2.src = "data:image/jpeg;base64," + base64enc;
    image2.height = 20;
    image2.width = 20;
    

    Then, the function that takes those 2 images:

    function getIcon(image1, image2){
      var canvas = document.createElement("canvas");
      canvas.width = image1.width;
      canvas.height = image1.height;
      var ctx = canvas.getContext("2d");
      ctx.drawImage(image1, 0, 0);
      ctx.drawImage(image2, 1, 1, 28, 28);
      var dataURL = canvas.toDataURL("image/png");
      return dataURL;
    }
    

    That is working fine (except a strange refresh problem: the image2 does not appear on the image1 when the page is loaded but it’s ok after a reload).

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

Sidebar

Related Questions

I have the following function that retrieves an image from a twitter feed, the
I use Google Chrome 7.0.x and I have the following javascript-function that gets called
Following some examples, I have a function that gets triggered on the 'register_deactivation_hook'. This
I have the following function that deletes the LaTeX command surrounding the current cursor
I have the following function that I am using to remove the characters \04
I have the following function that takes a number like 5 and creates a
I have the following function that is supposed to trigger anytime one of the
I have the following function that I only want to run inside <div id=imgWrapper>
I have the following structure and function that adds things to the structure: struct
I have the following part of a function that is driving me crazy. As

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.