{"id":19223956,"url":"https://github.com/sukov/jsresizelargeimages","last_synced_at":"2025-02-23T10:15:08.515Z","repository":{"id":69860172,"uuid":"113669590","full_name":"sukov/JSResizeLargeImages","owner":"sukov","description":"JavaScript for resizing large images","archived":false,"fork":false,"pushed_at":"2017-12-09T13:05:32.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-04T21:17:44.468Z","etag":null,"topics":["image-manipulation","image-processing","javascript"],"latest_commit_sha":null,"homepage":"","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/sukov.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-09T13:00:37.000Z","updated_at":"2017-12-09T13:05:14.000Z","dependencies_parsed_at":"2023-02-22T15:15:28.083Z","dependency_job_id":null,"html_url":"https://github.com/sukov/JSResizeLargeImages","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/sukov%2FJSResizeLargeImages","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukov%2FJSResizeLargeImages/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukov%2FJSResizeLargeImages/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sukov%2FJSResizeLargeImages/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sukov","download_url":"https://codeload.github.com/sukov/JSResizeLargeImages/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240298487,"owners_count":19779283,"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":["image-manipulation","image-processing","javascript"],"created_at":"2024-11-09T15:09:58.967Z","updated_at":"2025-02-23T10:15:08.504Z","avatar_url":"https://github.com/sukov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSResizeLargeImages\n\n## Source code\n\n```javascript\nfunction resizeLargeImages() {\n\timgArray = document.getElementsByTagName(\"img\");\n\tfor (var i = 0; i \u003c imgArray.length; i++) {\n\t\tif (imgArray[i] == null) { continue; }\n\t\tvar resizedCanvas = convertImageToCanvasAndResize(imgArray[i]);\n\t\tif (resizedCanvas != null) {\n\t\t\t// function convertCanvasToImage will throw error if canvas.toDataURL is not allowed\n\t\t//\tvar resizedImage = convertCanvasToImage(resizedCanvas);\n\t\t//\timgArray[i].parentNode.replaceChild(resizedImage, imgArray[i]);\n\t\t\t// image is replaced with resized canvas (recommended mode)\n\t\t\timgArray[i].parentNode.replaceChild(resizedCanvas, imgArray[i]); \n\t\t}\n\t}\n}\n\n function convertImageToCanvasAndResize(image) {\n \t\tvar maxWidth = 500; // Max width for the canvas\n        var maxHeight = 500;    // Max height for the canvas\n        var ratio = 0.0;  // Used for aspect ratio\n        var width = image.width;    // Current image width\n        var height = image.height;  // Current image height\n\n        // Check if the current width is larger than the max\n        if(width \u003e maxWidth) {\n            ratio = maxWidth / width;   // get ratio for scaling image\n        } else if(height \u003e maxHeight) {\n        \t\tratio = maxHeight / height; // get ratio for scaling image\n        } else {\n        \t\treturn; // image is smaller then maxWidth and maxHeight\n        }\n        \n        height = height * ratio;    // Reset height to match scaled image\n       \twidth = width * ratio;    // Reset width to match scaled image\n\t\tvar canvas = document.createElement(\"canvas\");\n\t\tcanvas.width = width\n\t\tcanvas.height = height\n\t\tcanvas.getContext(\"2d\").drawImage(image, 0, 0, width, height);\n\t\treturn canvas;\n }\n \n function convertCanvasToImage(canvas) {\n\tvar image = new Image();\n\timage.crossOrigin = \"Anonymous\";\n\timage.src = canvas.toDataURL(\"image/png\");\n\treturn image;\n}\n\ndocument.getElementsByTagName(\"body\")[0].onload = resizeLargeImages;\t// example usage\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsukov%2Fjsresizelargeimages","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsukov%2Fjsresizelargeimages","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsukov%2Fjsresizelargeimages/lists"}