{"id":24983691,"url":"https://github.com/posthtml/posthtml-img-autosize","last_synced_at":"2025-06-12T10:03:20.919Z","repository":{"id":3305627,"uuid":"48882011","full_name":"posthtml/posthtml-img-autosize","owner":"posthtml","description":"Auto setting the width and height of \u003cimg\u003e","archived":false,"fork":false,"pushed_at":"2023-01-06T15:10:29.000Z","size":411,"stargazers_count":28,"open_issues_count":13,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T21:06:05.504Z","etag":null,"topics":[],"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/posthtml.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/funding.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":"posthtml","open_collective":"posthtml","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2016-01-01T15:46:40.000Z","updated_at":"2023-07-27T10:33:48.000Z","dependencies_parsed_at":"2023-01-11T16:16:35.768Z","dependency_job_id":null,"html_url":"https://github.com/posthtml/posthtml-img-autosize","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-img-autosize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-img-autosize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-img-autosize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-img-autosize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posthtml","download_url":"https://codeload.github.com/posthtml/posthtml-img-autosize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480514,"owners_count":21110936,"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":[],"created_at":"2025-02-04T09:20:17.440Z","updated_at":"2025-04-11T20:51:46.474Z","avatar_url":"https://github.com/posthtml.png","language":"JavaScript","readme":"# posthtml-img-autosize [![npm version](https://badge.fury.io/js/posthtml-img-autosize.svg)](http://badge.fury.io/js/posthtml-img-autosize) [![Build Status](https://travis-ci.org/posthtml/posthtml-img-autosize.svg?branch=master)](https://travis-ci.org/posthtml/posthtml-img-autosize)\n\n[PostHTML](https://github.com/posthtml/posthtml) plugin that automatically sets `width` and `height` of `\u003cimg\u003e`.\nIt supports JPG, PNG, GIF, BMP, TIFF, SVG, and WebP.\nIt autosizes both local and remote images.\n\n\n## Usage\nBy default the plugin will autosize only images with `width=\"auto\"` and `height=\"auto\"`:\n\n```js\nvar posthtml = require('posthtml');\n\nposthtml([require('posthtml-img-autosize')()])\n    .process('\u003cimg src=\"photo.png\" width=\"auto\" height=\"auto\"\u003e\u003cimg src=\"user.jpg\"\u003e')\n    .then(function (result) {\n        console.log(result.html);\n    });\n\n// \u003cimg src=\"photo.png\" width=\"111\" height=\"52\"\u003e\n// \u003cimg src=\"user.jpg\"\u003e\n```\n\n\nBut if you set `processEmptySize: true`, the plugin will autosize all images with undefined or empty `width` and `height`:\n```js\nposthtml([\n        require('posthtml-img-autosize')({\n            root: './', // Path to images base directory (default: './')\n            processEmptySize: true\n        })\n    ])\n    .process('\u003cimg src=\"photo.png\" width=\"auto\" height=\"auto\"\u003e\u003cimg src=\"user.jpg\"\u003e')\n    .then(function (result) {\n        console.log(result.html);\n    });\n\n// \u003cimg src=\"photo.png\" width=\"111\" height=\"52\"\u003e\n// \u003cimg src=\"user.jpg\" width=\"100\" height=\"201\"\u003e\n```\n\n\n### Image versioning\nIf you use `?..` for image versioning in your HTML you should set `questionMarkAsVersion: true` in the config:\n```js\nposthtml([\n        require('posthtml-img-autosize')({\n            questionMarkAsVersion: true\n        })\n    ])\n     // The image file has \"photo.png\" name\n    .process('\u003cimg src=\"photo.png?v=2\" width=\"auto\" height=\"auto\"\u003e')\n    .then(function (result) {\n        console.log(result.html);\n    });\n\n// \u003cimg src=\"photo.png?v=2\" width=\"111\" height=\"52\"\u003e\n```\n\nWithout that option the plugin would search for a file with name `photo.png?v=2` on your disk.\n\n\n\n### Error handling\nYou can use the usual `Promise.catch()` to handle errors:\n\n```js\nposthtml([require('posthtml-img-autosize')()])\n    .process('\u003cimg src=\"notExists.jpg\" width=\"auto\" height=\"auto\"\u003e')\n    .then(function (result) {\n        // ...\n    })\n    .catch(function (error) {\n        console.log(error.message);\n    });\n\n// ENOENT: no such file or directory, open '/notExists.jpg'\n```\n","funding_links":["https://patreon.com/posthtml","https://opencollective.com/posthtml"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-img-autosize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthtml%2Fposthtml-img-autosize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-img-autosize/lists"}