{"id":19212373,"url":"https://github.com/leafo/imagesize","last_synced_at":"2026-02-03T05:32:34.288Z","repository":{"id":42123235,"uuid":"318621340","full_name":"leafo/imagesize","owner":"leafo","description":"Detect size \u0026 format of image file","archived":false,"fork":false,"pushed_at":"2022-04-12T18:46:32.000Z","size":33,"stargazers_count":9,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-06-28T10:42:42.006Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"MoonScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leafo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-04T19:54:21.000Z","updated_at":"2025-05-27T06:56:46.000Z","dependencies_parsed_at":"2022-08-12T07:11:18.652Z","dependency_job_id":null,"html_url":"https://github.com/leafo/imagesize","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/leafo/imagesize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fimagesize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fimagesize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fimagesize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fimagesize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leafo","download_url":"https://codeload.github.com/leafo/imagesize/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leafo%2Fimagesize/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29034234,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T02:28:16.591Z","status":"ssl_error","status_checked_at":"2026-02-03T02:27:48.904Z","response_time":96,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-09T13:46:43.812Z","updated_at":"2026-02-03T05:32:34.269Z","avatar_url":"https://github.com/leafo.png","language":"MoonScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# imagesize\n\n![test](https://github.com/leafo/imagesize/workflows/test/badge.svg)\n\nDetect the size of common image formats while trying to read as few bytes as\npossible. Byte strings are parsed using LPeg to extract headers from image\nformats\n\nSupported types:\n\n* PNG \u0026mdash; Typically needs at least 25 bytes\n* JPEG \u0026mdash; Typically needs around 160 for optimized images, upwards to around 1k or more with EXIF, etc.\n* GIF \u0026mdash; Reads with/height from first image descriptor. Typically needs around 700+ bytes, depends on how palette is stored\n\nThis library will only read the head of the string to identify the format and dimensions, then bail\nout. It will not verify that the file contains a valid image outside of that.\n\nLPeg does not support reading from a stream so you will have to append a buffer\ninto a string yourself and sequentially test it.\n\n## Install\n\n`luarocks install https://raw.githubusercontent.com/leafo/imagesize/main/imagesize-dev-1.rockspec`\n\n## Usage\n\n### `detect_image_from_bytes(byte_string)`\n\nAttempts to detect the type and dimensions of an image from the bytes passed in. It's\nnot necessary to pass the whole image, you can pass any amount of bytes and it\nwill attempt to read the front of the file up until where it can find the\ndimensions.\n\nOn success, two values are returned: the type of the image (`png`, `jpeg`,\n`gif`), and a table containing at least a `width` and `height` field.\n\nOn error, `nil` and an error message is returned.\n\n```lua\nlocal imagesize = require(\"imagesize\")\n\n-- this will attempt to detect the image from 200 bytes, but you're also\n-- welcome to pass the whole file\nlocal bytes = file.open(\"some_image.png\"):read(200)\n\nlocal kind, dimensions = imagesize.detect_image_from_bytes(bytes)\n\n-- kind --\u003e png\n-- dimensions --\u003e { width = 25, height = 100, depth = 8 }\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafo%2Fimagesize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleafo%2Fimagesize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleafo%2Fimagesize/lists"}