{"id":19057429,"url":"https://github.com/femessage/img-preview","last_synced_at":"2025-07-18T10:33:08.605Z","repository":{"id":56377981,"uuid":"161145522","full_name":"FEMessage/img-preview","owner":"FEMessage","description":"🖼Preview your img  easily","archived":false,"fork":false,"pushed_at":"2020-11-11T10:29:08.000Z","size":4966,"stargazers_count":7,"open_issues_count":4,"forks_count":8,"subscribers_count":3,"default_branch":"dev","last_synced_at":"2025-06-28T14:04:30.198Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://femessage.github.io/img-preview/","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/FEMessage.png","metadata":{"files":{"readme":"README-zh.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-12-10T08:53:55.000Z","updated_at":"2020-11-11T10:25:22.000Z","dependencies_parsed_at":"2022-08-15T17:40:23.366Z","dependency_job_id":null,"html_url":"https://github.com/FEMessage/img-preview","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/FEMessage/img-preview","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FEMessage%2Fimg-preview","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FEMessage%2Fimg-preview/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FEMessage%2Fimg-preview/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FEMessage%2Fimg-preview/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FEMessage","download_url":"https://codeload.github.com/FEMessage/img-preview/tar.gz/refs/heads/dev","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FEMessage%2Fimg-preview/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265742645,"owners_count":23820875,"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":"2024-11-08T23:57:20.241Z","updated_at":"2025-07-18T10:33:08.578Z","avatar_url":"https://github.com/FEMessage.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# img-preview\n\n[![Build Status](https://travis-ci.com/FEMessage/img-preview.svg?branch=master)](https://travis-ci.com/FEMessage/img-preview)\n[![NPM Download](https://img.shields.io/npm/dm/@femessage/img-preview.svg)](https://www.npmjs.com/package/@femessage/img-preview)\n[![NPM Version](https://img.shields.io/npm/v/@femessage/img-preview.svg)](https://www.npmjs.com/package/@femessage/img-preview)\n[![NPM License](https://img.shields.io/npm/l/@femessage/img-preview.svg)](https://github.com/FEMessage/img-preview/blob/master/LICENSE)\n[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/FEMessage/img-preview/pulls)\n[![Automated Release Notes by gren](https://img.shields.io/badge/%F0%9F%A4%96-release%20notes-00B2EE.svg)](https://github-tools.github.io/github-release-notes/)\n\n图片预览组件\n\n## Table of Contents \u003c!-- omit in toc --\u003e\n\n* [Feature](#feature)\n* [Demo](#demo)\n* [Install](#install)\n* [图片比例算法](#图片比例算法)\n* [Contributors](#contributors)\n* [License](#license)\n\n## Feature\n\n* 参考 medium 实现\n* 自动适配屏幕大小\n* 小图不模糊，大图不溢出屏幕\n* 支持按 `ESC` 键关闭预览\n\n[⬆ Back to Top](#table-of-contents)\n\n## Demo\n\n* [doc and online demo](https://femessage.github.io/img-preview/)\n\n[⬆ Back to Top](#table-of-contents)\n\n## Install\n\n```sh\nyarn add @femessage/img-preview\n```\n\n[⬆ Back to Top](#table-of-contents)\n\n## 图片比例算法\n\n当预览的图片原尺寸比较大的情况，需要把图片按比例预览\n\n```sh\n// x轴比例 = 窗口的宽 / 图片的宽\n// y轴比例 = 窗口的高 / 图片的高\n图片比例 = x轴比例 x 图片高度 \u003e 窗口高度 ? y轴比例 : x轴比例\n```\n\n以下是公式说明：\n\n* 第一步，计算 `x轴比例`（浏览器窗口宽度与图片原本宽度的比例），并保存下来\n\n![image-20181210204220704](https://i.loli.net/2019/11/15/eikTUwbqa4pmR3j.jpg)\n\n* 第二步，考虑到在`x轴比例`下，有可能图片的高度比窗口的高度还大。\n\n  这时应使用 `y轴比例` （浏览器窗口高度与图片原本高度的比例）作为图片的预览比例\n\n![image-20181211141542119](https://i.loli.net/2019/11/15/YEsxZ5fG9CdimHh.jpg)\n\n[⬆ Back to Top](#table-of-contents)\n\n## Contributors\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\n\u003c!-- prettier-ignore --\u003e\n\u003ctable\u003e\u003ctr\u003e\u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/listars\"\u003e\u003cimg src=\"https://avatars2.githubusercontent.com/u/20613509?v=4\" width=\"100px;\" alt=\"listars\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003elistars\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/FEMessage/img-preview/commits?author=listars\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"https://github.com/FEMessage/img-preview/commits?author=listars\" title=\"Documentation\"\u003e📖\u003c/a\u003e \u003ca href=\"#ideas-listars\" title=\"Ideas, Planning, \u0026 Feedback\"\u003e🤔\u003c/a\u003e\u003c/td\u003e\u003ctd align=\"center\"\u003e\u003ca href=\"https://github.com/donaldshen\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/19591950?v=4\" width=\"100px;\" alt=\"Donald Shen\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eDonald Shen\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/FEMessage/img-preview/issues?q=author%3Adonaldshen\" title=\"Bug reports\"\u003e🐛\u003c/a\u003e \u003ca href=\"#maintenance-donaldshen\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\u003ctd align=\"center\"\u003e\u003ca href=\"https://evila.me\"\u003e\u003cimg src=\"https://avatars3.githubusercontent.com/u/19513289?v=4\" width=\"100px;\" alt=\"EVILLT\"/\u003e\u003cbr /\u003e\u003csub\u003e\u003cb\u003eEVILLT\u003c/b\u003e\u003c/sub\u003e\u003c/a\u003e\u003cbr /\u003e\u003ca href=\"https://github.com/FEMessage/img-preview/commits?author=evillt\" title=\"Code\"\u003e💻\u003c/a\u003e \u003ca href=\"#maintenance-evillt\" title=\"Maintenance\"\u003e🚧\u003c/a\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/table\u003e\n\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n[⬆ Back to Top](#table-of-contents)\n\n## License\n\n[MIT](./LICENSE)\n\n[⬆ Back to Top](#table-of-contents)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffemessage%2Fimg-preview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffemessage%2Fimg-preview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffemessage%2Fimg-preview/lists"}