{"id":22611161,"url":"https://github.com/kelen/imagefileconvert","last_synced_at":"2025-04-11T07:46:23.263Z","repository":{"id":57271992,"uuid":"156154355","full_name":"KELEN/ImageFileConvert","owner":"KELEN","description":"image util to handle take picture","archived":false,"fork":false,"pushed_at":"2020-04-09T07:35:26.000Z","size":95,"stargazers_count":21,"open_issues_count":0,"forks_count":7,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-02T02:01:43.935Z","etag":null,"topics":["canvas","image","image-to-base64","image-to-canvas","image-translate"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KELEN.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-05T03:17:37.000Z","updated_at":"2022-08-27T00:09:32.000Z","dependencies_parsed_at":"2022-08-25T06:43:25.103Z","dependency_job_id":null,"html_url":"https://github.com/KELEN/ImageFileConvert","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KELEN%2FImageFileConvert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KELEN%2FImageFileConvert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KELEN%2FImageFileConvert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KELEN%2FImageFileConvert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KELEN","download_url":"https://codeload.github.com/KELEN/ImageFileConvert/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248359420,"owners_count":21090525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["canvas","image","image-to-base64","image-to-canvas","image-translate"],"created_at":"2024-12-08T16:09:37.760Z","updated_at":"2025-04-11T07:46:23.245Z","avatar_url":"https://github.com/KELEN.png","language":"JavaScript","readme":"# ImageFileConvert\n\n\u003e image util to handle image file, canvas/image/blob/file translate\n\n## [demo](https://kelen.github.io/ImageFileConvert/example/)\n\n## USAGE\n\n\u003e copy dist imageFileConvert.umd.js for usage\n\n### USE NPM\n\n```\nnpm i image-file-convert\n\nimport ImageFileConvert from 'image-file-convert'\n```\n\n```html\n\u003cinput type=\"file\" accept=\"image/*\" onchange=\"fileChange(event)\"\u003e\n\u003cscript src=\"../dist/imageFileConvert.umd.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\nfunction fileChange(ev) {\n  let file = ev.target.files[0];\n  ImageFileConvert.getImageFileData(file, { width: 600, height: 800, cover: false }).then(({ blob, base64 }) =\u003e {\n    let img = ImageFileConvert.blobToImage(blob);\n    img.style.width = '300px';\n    console.log(blob, base64.length)\n    document.body.appendChild(img);\n  });\n}\n\u003c/script\u003e\n```\n\n## API\n\n#### getImageFileData(file, option);\n\n\u003e  get image file input data, can compress size with option with and height\n\n| 参数 | 类型 | 说明 |\n| --- | --- | --- |\n| file | file type | 文件类型 |\n| option | object | 配置项 |\n|  | width | 宽度 |\n|  | height | 高度 |\n|  | cover | 是否覆盖整个区域，默认false |\n\n```javascript\nfunction fileChange(ev) {\n  let file = ev.target.files[0];\n  ImageFileConvert.getImageFileData(file, { width: 300, height: 400, cover: true }).then(blob =\u003e {\n    let img = ImageFileConvert.blobToImage(blob);\n    document.body.appendChild(img);\n  })\n}\n```\n\n#### blobToImage(blob)\n\n\u003e blob translate to image, use for ImageFileData() result\n\n| 参数 | 类型 | 说明 |\n| --- | --- | --- |\n| blob | blob | 二进制文件 |\n\n```javascript\nlet img = ImageFileConvert.blobToImage(blob);\n```\n\n\n#### fileToCanvas(file, option);\n\n\u003e file translate to canvas and image, get canvas and image\n\n| 参数 | 类型 | 说明 |\n| --- | --- | --- |\n| file | file type | 文件类型 |\n| option | object | 配置项 |\n|  | width | 宽度 |\n|  | height | 高度 |\n|  | cover | 是否覆盖整个区域，默认false |\n\n```javascript\nImageFileConvert.fileToCanvas(file, { width: 400, height: 400 }).then(({ canvas, image }) =\u003e {\n  document.body.appendChild(canvas);\n})\n```\n\n#### fileToImage(file);\n\n\u003e file translate to image\n\n| 参数 | 类型 | 说明 |\n| --- | --- | --- |\n| file | file type | 文件类型 |\n\n```javascript\nImageFileConvert.fileToImage(file).then(img =\u003e {\n    document.body.appendChild(img);\n})\n```\n\n#### imageToCanvas(img);\n\n\u003e  image translate to canvas\n\n| 参数 | 类型 | 说明 |\n| --- | --- | --- |\n| img | image element | 图片 |\n\n```javascript\nlet canvas = ImageFileConvert.imageToCanvas(img);\n```\n\n#### canvasToImage(canvas);\n\n\u003e canvas tranlate to image, return promise\n\n| 参数 | 类型 | 说明 |\n| --- | --- | --- |\n| canvas | canvas | canvas |\n\n\n```javascript\nImageFileConvert.canvasToImage(cvs, 'image/png').then(canvas =\u003e {\n  document.body.append(canvas);\n})\n```\n\n#### canvasToFile(canvas);\n\n\u003e canvas translate to file\n\n```javascript\nlet file = ImageFileConvert.canvasToFile(cvs);\n```\n\n### canvasToBase64(canvas, type = 'image/png', encoderOptions = '0.92');\n\n\u003e canvas to base64\n\n```javascript\nlet base64 = ImageFileConvert.canvasToBase64(cvs);\n```\n\n#### imageToBase64(img);\n\n\u003e image translate to base64\n\n```javascript\nlet base64 = ImageFileConvert.imageToBase64(img);\n```\n\n#### rotate(canvas, image, degree);\n\n\u003e rotate image by canvas and return canvas\n\n| 参数 | 类型 | 说明 |\n| --- | --- | --- |\n| canvas | canvas | 需要绘制的canvs |\n| image | img | img元素 |\n| degree  | int | 角度 |\n\n```javascript\nImageFileConvert.rotate(cvs, img, degree);\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelen%2Fimagefileconvert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkelen%2Fimagefileconvert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkelen%2Fimagefileconvert/lists"}