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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:48:25+00:00 2026-05-27T05:48:25+00:00

I have created an image in my Canvas with HTML5 and I saved it.

  • 0

I have created an image in my Canvas with HTML5 and I saved it. My code looks like the one here, in this example:
http://www.worldofwebcraft.com/page.php?id=101&t=HTML5_use_php_and_ajax_to_save_canvas_as_png_on_your_server

My problem is that when I save my image, the whole canvas it is saved and not only the part of it that has a draw on it. So I get an image with a big, transparent background, behind my image, and the image instead of be 50×50 for example, becomes 100×100.

Is there a way to trim this transparent background, either in the JavaScript site, before send the data to the php file, or in the PHP file, after save the image?

Thanks in advance

  • 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-05-27T05:48:26+00:00Added an answer on May 27, 2026 at 5:48 am

    If you know what part of the canvas you want. You can create a new canvas element and make it the right size for you and then draw bit of the image you want onto the new canvas and then just do the same thing you are doing but for the second smaller canvas.

    var smallCanvas = document.createElement('canvas');
    smallCanvas.width = somewidth
    smallCanvas.height = someheight
    var smCtx = smallCanvas.getContext('2d');
    smCtxdrawImage(oldCanvas, sx, sy, sw, sh, dx, dy, dw, dh)
    

    takes an oldCanvas, clips it to the rectangle(sx, sy, sw, sh), scales it to dimensions (dw, dh), and draws it on the smallCanvas at coordinates (dx, dy).

    EDIT:
    As per my comment here is a Jquery plugin that does what I have been suggesting.
    Here

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

Sidebar

Related Questions

I have a renderer that looks like this: <s:ItemRenderer xmlns:fx=http://ns.adobe.com/mxml/2009 xmlns:s=library://ns.adobe.com/flex/spark xmlns:mx=library://ns.adobe.com/flex/mx autoDrawBackground=true> <s:Group
I have created a Facebook Canvas App. This canvas app is essentially an image
i have two Activity in this i take pixels of image from one activity
I have an upcoming project that I would like to use the HTML5 canvas
I would like to show an image on Canvas(HTML5) so that I will be
I have an animated .GIF image that I created with http://ajaxload.info/ and some editing.
I have created jquery image slider and it is working good. However i have
I have created a XML image gallery, which displays text in between each slide.
I have created PHP GD image for captcha, file called image.php each time it
I have a dynamically created image that I am saving to a stream so

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.