{"id":50338343,"url":"https://github.com/mathsgod/html-image-extractor","last_synced_at":"2026-05-29T15:01:12.961Z","repository":{"id":351888874,"uuid":"1212287148","full_name":"mathsgod/html-image-extractor","owner":"mathsgod","description":"Extract embedded data: URI images from HTML and replace with placeholders","archived":false,"fork":false,"pushed_at":"2026-04-16T08:28:49.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-17T00:17:45.379Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","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/mathsgod.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-16T08:24:32.000Z","updated_at":"2026-04-16T08:28:54.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mathsgod/html-image-extractor","commit_stats":null,"previous_names":["mathsgod/html-image-extractor"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/mathsgod/html-image-extractor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fhtml-image-extractor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fhtml-image-extractor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fhtml-image-extractor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fhtml-image-extractor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathsgod","download_url":"https://codeload.github.com/mathsgod/html-image-extractor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathsgod%2Fhtml-image-extractor/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33657690,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-29T02:00:06.066Z","response_time":107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":"2026-05-29T15:01:11.581Z","updated_at":"2026-05-29T15:01:12.954Z","avatar_url":"https://github.com/mathsgod.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# html-image-extractor\n\nA PHP library to extract embedded `data:` URI images from HTML, replace them with temporary placeholders, and restore them with real URLs once the images have been saved or uploaded.\n\n## Requirements\n\n- PHP 8.1+\n\n## Installation\n\n```bash\ncomposer require mathsgod/html-image-extractor\n```\n\n## How it works\n\n```\nHTML (with data: URIs)\n    ↓ extract()\nHTML with __IMG_xxx__ placeholders  +  image data map\n    ↓ save / upload images, get URLs\n    ↓ restore()\nFinal HTML (with real URLs)\n```\n\n## Usage\n\n### Basic — save to local directory\n\n```php\nuse HtmlImageExtractor\\HtmlImageExtractor;\n\n$extractor = new HtmlImageExtractor();\n\n// Step 1: extract embedded images\n$extractor-\u003eextract($html);\n\n$modifiedHtml = $extractor-\u003egetHtml();   // HTML with __IMG_xxx__ placeholders\n$images       = $extractor-\u003egetImages(); // image data map\necho $extractor-\u003ecount() . ' image(s) found';\n\n// Step 2: save to disk and get URL map\n$urlMap = $extractor-\u003esaveToDir(\n    saveDir: __DIR__ . '/uploads',\n    baseUrl: 'https://example.com/uploads'\n);\n\n// Step 3: restore placeholders with real URLs\n$finalHtml = $extractor-\u003erestore($urlMap);\n```\n\n### Advanced — custom upload (e.g. cloud storage)\n\n```php\n$extractor-\u003eextract($html);\n\n// Build the URL map yourself after uploading\n$urlMap = [];\nforeach ($extractor-\u003egetImages() as $id =\u003e $info) {\n    // $info['mimeType']  — e.g. \"image/png\"\n    // $info['data']      — base64 encoded image data\n    // $info['extension'] — e.g. \"png\"\n    $url = myCloudUpload(base64_decode($info['data']), $info['mimeType']);\n    $urlMap[$id] = $url;\n}\n\n$finalHtml = $extractor-\u003erestore($urlMap);\n```\n\n## API\n\n| Method | Description |\n|--------|-------------|\n| `extract(string $html): static` | Extract all `data:` URI images and replace with placeholders. Returns `$this` for chaining. |\n| `getHtml(): string` | Get the HTML with placeholders (after `extract()`). |\n| `getImages(): array` | Get extracted image data keyed by placeholder ID. Each entry has `mimeType`, `data` (base64), `extension`. |\n| `count(): int` | Number of images found in the last `extract()` call. |\n| `saveToDir(string $saveDir, string $baseUrl): array` | Save images to a local directory. Returns a `urlMap` ready for `restore()`. |\n| `restore(array $urlMap): string` | Replace placeholders with real URLs. Returns final HTML. |\n\n## Supported image formats\n\n`jpeg`, `png`, `gif`, `webp`, `svg`, `bmp`, `tiff`, `avif`\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathsgod%2Fhtml-image-extractor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathsgod%2Fhtml-image-extractor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathsgod%2Fhtml-image-extractor/lists"}