Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html2canvas border radius not applying to img tag #399

Closed
faiq-naseem opened this issue Jun 15, 2014 · 14 comments
Closed

html2canvas border radius not applying to img tag #399

faiq-naseem opened this issue Jun 15, 2014 · 14 comments
Labels

Comments

@faiq-naseem
Copy link

Need help, when i apply border radius to image via css, Not rendering.
See demo
http://faiqnaseem.com/html2canvas/

<style> #mydiv { width: 300px; height: 200px; background:#000; } #mydiv img { width: 200px; height: 200px; border-radius:100%; } </style>

Resultant displayed image not showing border radius,Just without radius i need to apply radius only through this method.

if i used image as background, it works but i need to put image in div tag, it is dynamically adding from database..

untitled

@faiq-naseem
Copy link
Author

@niklasvh pls advice

@DavidBruchmann
Copy link

mhm, border radius 100%?
maybe take another unit.
No idea how 100% is interpreted by browsers here ...

On Sun, Jun 15, 2014 at 6:41 PM, faiq-naseem notifications@github.com
wrote:

@niklasvh https://github.com/niklasvh pls advice


Reply to this email directly or view it on GitHub
#399 (comment)
.

@faiq-naseem
Copy link
Author

@DavidBruchmann we can use 100% but even 100px is not working

@faiq-naseem
Copy link
Author

See demo
http://faiqnaseem.com/html2canvas/

Generated image should same as preview image

@DavidBruchmann
Copy link

ok, now I understand.
what if you use border-radius smaller than 50%?

@faiq-naseem
Copy link
Author

nothing happens even smaller than 50%.

@DavidBruchmann
Copy link

what if you add a border like border: 1px solid black; ?

@faiq-naseem
Copy link
Author

i want border-radius, not border only :)

Image should be rounded, which can only be done from border-radius

@DavidBruchmann
Copy link

ok, seems I can't help here.
I understand your purpose and used border-radius without border too already, just thought border could convince html2canvas too perhaps ;-)

@usmonster
Copy link
Contributor

FYI, seems exactly the issue reported in #346.

@niklasvh
Copy link
Owner

niklasvh commented Oct 7, 2014

Fixed

@niklasvh niklasvh closed this as completed Oct 7, 2014
@uaison
Copy link

uaison commented Jan 12, 2016

I met the same problem with you, and then, have you solve the problem?

@uaison
Copy link

uaison commented Jan 13, 2016

The following functions can solve this problem:
function CanvalHD(canvasThis,ctxThis){
(function (canvas, ctx) {
var devicePixelRatio = window.devicePixelRatio || 1;
var backingStorePixelRatio = ctx.webkitBackingStorePixelRatio ||
ctx.mozBackingStorePixelRatio ||
ctx.msBackingStorePixelRatio ||
ctx.oBackingStorePixelRatio ||
ctx.backingStorePixelRatio || 1;
var ratio = devicePixelRatio / backingStorePixelRatio;
if (devicePixelRatio !== backingStorePixelRatio) {
var oldWidth = canvas.width;
var oldHeight = canvas.height;
canvas.width = oldWidth * ratio;
canvas.height = oldHeight * ratio;
canvas.style.width = oldWidth + 'px';
canvas.style.height = oldHeight + 'px';
ctx.scale(ratio, ratio);
}
})(canvasThis, ctxThis);
}

This is due to the different of screen pixels ratio, iPhone screen is 2, PC display is 1, and Android screen is 1.5,
See the website:
http://segmentfault.com/q/1010000002533478

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants