{"id":13535744,"url":"https://github.com/alessiomaffeis/vue-picture-input","last_synced_at":"2025-05-15T03:08:49.687Z","repository":{"id":17704106,"uuid":"82540897","full_name":"alessiomaffeis/vue-picture-input","owner":"alessiomaffeis","description":"Mobile-friendly picture file input component for Vue.js 2-3 with image preview, drag and drop, EXIF orientation, and more","archived":false,"fork":false,"pushed_at":"2024-03-29T05:50:30.000Z","size":2282,"stargazers_count":888,"open_issues_count":7,"forks_count":156,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-12T08:22:46.027Z","etag":null,"topics":["component","image","input","picture","preview","vue"],"latest_commit_sha":null,"homepage":"","language":"Vue","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/alessiomaffeis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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-02-20T09:37:12.000Z","updated_at":"2025-04-29T12:41:16.000Z","dependencies_parsed_at":"2024-01-17T16:57:00.602Z","dependency_job_id":"3d51d48c-48ae-4f9c-bad1-8a3c2b300e5f","html_url":"https://github.com/alessiomaffeis/vue-picture-input","commit_stats":{"total_commits":201,"total_committers":25,"mean_commits":8.04,"dds":0.527363184079602,"last_synced_commit":"5970ccefcf62f9bef251aaea6cc4a43d40ea20a4"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiomaffeis%2Fvue-picture-input","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiomaffeis%2Fvue-picture-input/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiomaffeis%2Fvue-picture-input/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alessiomaffeis%2Fvue-picture-input/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alessiomaffeis","download_url":"https://codeload.github.com/alessiomaffeis/vue-picture-input/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254264771,"owners_count":22041794,"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":["component","image","input","picture","preview","vue"],"created_at":"2024-08-01T09:00:25.225Z","updated_at":"2025-05-15T03:08:44.677Z","avatar_url":"https://github.com/alessiomaffeis.png","language":"Vue","funding_links":[],"categories":["Vue","UI组件"],"sub_categories":[],"readme":"vue-picture-input\n=============\n\nMobile-friendly picture file input component for Vue.js 2-3 with image preview, drag and drop, EXIF orientation, and more.\n\n![vue-pictur-input-demo](https://user-images.githubusercontent.com/2185511/167262626-5f10679f-70cf-4477-865a-508c67bca44e.gif)\n\n## Installation\n\n### npm\n\n``` sh\nnpm install --save vue-picture-input\n```\n### yarn\n\n``` sh\nyarn add vue-picture-input\n```\n\n## Usage\n\n```HTML\n\u003ctemplate\u003e\n  \u003cdiv class=\"hello\"\u003e    \n    \u003cpicture-input \n      ref=\"pictureInput\"\n      width=\"600\" \n      height=\"600\" \n      margin=\"16\" \n      accept=\"image/jpeg,image/png\" \n      size=\"10\" \n      button-class=\"btn\"\n      :custom-strings=\"{\n        upload: '\u003ch1\u003eBummer!\u003c/h1\u003e',\n        drag: 'Drag a 😺 GIF or GTFO'\n      }\"\n      @change=\"onChange\"\u003e\n    \u003c/picture-input\u003e\n  \u003c/div\u003e\n\u003c/template\u003e\n```\n\n```javascript\n\u003cscript\u003e\nimport PictureInput from 'vue-picture-input'\n\nexport default {\n  name: 'app',\n  data () {\n    return {\n    }\n  },\n  components: {\n    PictureInput\n  },\n  methods: {\n    onChange (image) {\n      console.log('New picture selected!')\n      if (image) {\n        console.log('Picture loaded.')\n        this.image = image\n      } else {\n        console.log('FileReader API not supported: use the \u003cform\u003e, Luke!')\n      }\n    }\n  }\n}\n\u003c/script\u003e\n```\n\nYou can also use it directly in the browser through [unpkg's CDN](https://unpkg.com/vue-picture-input) (or [jsDelivr](https://cdn.jsdelivr.net/npm/vue-picture-input)):\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n  \u003cscript src=\"https://unpkg.com/vue\"\u003e\u003c/script\u003e\n  \u003cscript src=\"https://unpkg.com/vue-picture-input\"\u003e\u003c/script\u003e\n  \u003ctitle\u003eIn the browser!\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003cdiv id=\"app\"\u003e\n    \u003cp\u003e{{ message }}\u003c/p\u003e\n    \u003cpicture-input\u003e\u003c/picture-input\u003e\n  \u003c/div\u003e\n  \u003cscript\u003e\n    var app = new Vue({\n      el: '#app',\n      data: {\n        message: 'Hello Vue!'\n      },\n      components: {\n        'picture-input': PictureInput\n      }\n    })\n  \u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Example project\n\nTry it on CodeSandbox: https://codesandbox.io/s/github/alessiomaffeis/vue-picture-input-example\n\n\n## Props\n\n- **width, height**: (pixels, optional) the maximum width and height of the preview container. The picture will be resized and centered to cover this area. If width is not specified, the preview container will expand to full width. If height is not specified, it will be set equal to width.\n- **crop**: (boolean, optional) set *:crop=\"false\"* if you wish to disable cropping. The image will be resized and centered in order to be fully contained in the preview container. Default value: true.\n- **margin**: (pixels, optional) the margin around the preview container. Default value: 0.\n- **radius**: (percentage, optional) The border-radius value for the container. Set *radius=\"50\"* to get a circular container. Default value: 0.\n- **plain**: (boolean, optional) Set *:plain=\"true\"* to remove the inner border and text. Default value: false.\n- **accept**: (media type, optional) the accepted image type(s), e.g. image/jpeg, image/gif, etc. Default value: 'image/*'. \n- **size**: (MB, optional) the maximum accepted file size in megabytes.\n- **removable**: (boolean, optional) set *:removable=\"true\"* if you want to display a \"Remove Photo\" button. Default value: false.\n- **hideChangeButton**: (boolean, optional) set *:hideChangeButton=\"true\"* if you want to hide the \"Change Photo\" button. Default value: false.\n- **id, name**: (string, optional) the id and name attributes of the HTML input element.\n- **buttonClass**: (string, optional) the class which will be applied to the 'Change Photo' button.\n  Default value: 'btn btn-primary button'.\n- **removeButtonClass**: (string, optional) the class which will be applied to the 'Remove Photo' button.\n  Default value: 'btn btn-secondary button secondary'.\n- **prefill**: (image url or File object, optional) use this to specify the path to a default image (or a File object) to prefill the input with. Default value: empty.\n- **prefillOptions**: (object, optional) use this if you prefill with a data uri scheme to specify a file name and a media or file type:\n```\n  fileName: (string, optional) the file name\n  fileType: (string, optional) the file type of the image, i.e. \"png\", or\n  mediaType: (string, optional) the media type of the image, i.e. \"image/png\"\n```\n- **toggleAspectRatio**: (boolean, optional) set *:toggleAspectRatio=\"true\"* to show a button for toggling the canvas aspect ratio (Landscape/Portrait) on a non-square canvas. Default value: false.\n- **autoToggleAspectRatio**: (boolean, optional) set *:autoToggleAspectRatio=\"true\"* to enable automatic canvas aspect ratio change to match the selected picture's. Default value: false.\n- **changeOnClick**: (boolean, optional) set *:changeOnClick=\"true\"* to open image selector when user click on the image. Default value: true.\n- **aspectButtonClass**: (string, optional) the class which will be applied to the 'Landscape/Portrait' button.\n  Default value: 'btn btn-secondary button secondary'.\n- **zIndex**: (number, optional) The base z-index value. In case of issues with your layout, change *:zIndex=\"...\"* to a value that suits you better. Default value: 10000.\n- **alertOnError**: (boolean, optional) Set *:alertOnError=\"false\"* to disable displaying alerts on attemps to select file with\nwrong type or too big.\nDefault value: true.\n- **customStrings**: (object, optional) use this to provide one or more custom strings (see the example above). Here are the available strings and their default values:\n- **capture**: (string, optional) use this if you want to allow image capture from capture devices (e.g. camera)\n\n```js\n{\n  upload: '\u003cp\u003eYour device does not support file uploading.\u003c/p\u003e', // HTML allowed\n  drag: 'Drag an image or \u003cbr\u003eclick here to select a file', // HTML allowed\n  tap: 'Tap here to select a photo \u003cbr\u003efrom your gallery', // HTML allowed\n  change: 'Change Photo', // Text only\n  remove: 'Remove Photo', // Text only\n  select: 'Select a Photo', // Text only\n  selected: '\u003cp\u003ePhoto successfully selected!\u003c/p\u003e', // HTML allowed\n  fileSize: 'The file size exceeds the limit', // Text only\n  fileType: 'This file type is not supported.', // Text only\n  aspect: 'Landscape/Portrait' // Text only\n}\n```\n   \n## Events\n\n- **change**: emitted on (successful) picture change (prefill excluded). The image is passed along with the event as a Base64 Data URI string. If you need to access the underlying image from the parent component, add a *ref* attribute to picture-input (see the example above). You may want to use *this.$refs.pictureInput.image* (Base64 Data URI string) or *this.$refs.pictureInput.file* (File Object)\n- **prefill**: emitted on default image prefill.\n- **remove**: emitted on picture remove.\n- **click**: emitted on picture click.\n- **error**: emitted on error, along with an object with *type*, *message*, and optional additional parameters.\n  \n## TODOs\n\n- Client-side resizing and cropping\n- Add tests\n\n## Contributions\n\nAll contributions are welcome, as long as they are within the scope of the project. Please open a new issue before submitting a pull request.\n\nYou should follow the Javascript Standard Style guidelines:\nhttps://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falessiomaffeis%2Fvue-picture-input","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falessiomaffeis%2Fvue-picture-input","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falessiomaffeis%2Fvue-picture-input/lists"}