-
Notifications
You must be signed in to change notification settings - Fork 4
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
Saving canvas with 300dpi (imagemagick) and todataurl / base64 #153
Comments
DPI means dots per inch, not dots per centimeter. 300 DPI(dot/in) = 118 dpcm (dot/cm) The calculations should be: 29.7 centimeters: 29.7*118 = 3504.6 52 centimeters: 52*118 = 6136 I hope this helps solving your problem. (I cannot give comments, yet. So I put this as an answer) |
Help? canvas.toDataURL('image/jpeg') at 300dpi instead of 72? I have already setup the canvas at 1800px × 1200px (4x6 @ 300dpi) and am using to have them download it, but when they try to print, it is monstrously huge because it is scaled @72dpi instead of @300dpi. Can anyone come up with a way to specify the dpi of the image when creating the DataURL or when downloading that doesn't involve PHP? |
Sorry, another friend just found this package for me, and it's working perfectly: changeDPI |
changeDPIchangeDPI provides 2 utility functions that can change the dpi of canvas-generated image, of either dataUrl or blob formats. The functions separate the header from the image data, convert and manipulate just the header, then sticks the header back on the file. In this way, very large images can be converted quickly without having to convert the entire contents of an image file. This process is non-destructive—image data does not get modified in the process. InstallThis project depends on node and npm. npm install --save changedpi UsageFrom a canvas element dataUrl: // create the dataUrl at standard 72dpi
var dataUrl = canvas.toDataURL('image/jpeg', 0.92);
var daurl150dpi = changeDpiDataUrl(dataUrl, 150); From a canvas element blob: // create the blob at standard 72dpi
canvas.toBlob(function(blob) {
changeDpiBlob(blob, 300).then(function(blob){
// use your changed blob
})
},'image/jpeg', 0.92); TODO add example with file reader. ES6This module uses ES6. To see a compiled ES5 version, run Testingnpm install .
npm run test ContributePlease do contribute! Open an issue or submit a pull request. The project falls under @Shutterstock's Code of Conduct. LicenseMIT. |
Add dpi/scale options for custom resolutionFeature: Custom resolution with DPI/scale optionsImplementationWhen a custom scale is set, the canvas' width/height are multiplied by that scale while keeping its CSS width/height at the original. Then ctx.scale is used to scale all future canvas actions (see here for more info). The option Here's some example usage:
|
@marcialwushu this is great! thank you for posting this solution, it works like a charm |
I have a problem saving my canvas. I think that is because my canvas is too large. I have asked for help here:
Elements on the canvas disappear w/ jsfiddle
canvas.toDataURL() for large canvas
… but no success.
My problem is the next:
I have a canvas for example with these dimensions: 1123x1965 pixels and I need to resize to 29.7x52 centimeters and put them in 300dpi.
My rational was as follows:
After the edited template, convert to full size and then save a png image to the actual size in pixels, already multiplied by 300 dpi. Made this calculation:
29.7 centimeters: 29.7*300 = 8910
52 centimeters: 52*300 = 15600
The problem on using this is basically canvas disappear. Please look this: Elements on the canvas disappear w/ jsfiddle
And todataurl function don’t work: canvas.toDataURL() for large canvas
PixelsPerCentimeter -density 300 test2.png
Anyone can help me?
Thank You.
The text was updated successfully, but these errors were encountered: