npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@sergtyapkin/image-uploader

v1.1.10

Published

### Contents: > - [ES6 lib interface](#es6-lib-interface) > - [Vue.js component](#vuejs-component)

Downloads

358

Readme

Static Badge Static Badge npm

ES6 lib or Vue.js module "Get image as base64"

Contents:

ES6 lib interface:

There are 2 functions. All of them returns gotten image in base64 url encoding: import {loadImageInBase64, draggedImageToBase64} from "@sergtyapkin/images-uploader"

1. To get image thorough filesystem dialogue:

/**
 * Opens user file selection (with filter to images) dialog and returns dataURL of selected image.
 * Image is cropped to the specified size
 *
 * @param cropToSquare is results dataUrl must be a square with size of minimal image side, if null => dataUrl with the size of an original image
 * @param compressSize size to compress the longest side in, if null => dataUrl with the size of an original image
 * @param maxFileSizeMB maximum allowed file size
 * @param acceptExtensions list with allowed mime types
 * @returns Data url of image selected by user
 */
export async function loadImageInBase64(
  cropToSquare: boolean,
  compressSize?: number,
  maxFileSizeMB?: number,
  acceptExtensions: string[] = DEFAULT_ACCEPT,
) {
  // ...
}

2. To get image thorough drag and drop or any other file loaders

/**
 * Validate loaded (for example by drag-n-drop) image file and returns dataURL of selected image.
 * Image is cropped to the specified size
 *
 * @param dataTransfer data of all loaded files (you can get in using event.dataTransfer)
 * @param cropToSquare is results dataUrl must be a square with size of minimal image side, if null => dataUrl with the size of an original image
 * @param compressSize size to compress the longest side in, if null => dataUrl with the size of an original image
 * @param maxFileSizeMB maximum allowed file size
 * @returns Data url of image loaded by user
 */
export function draggedImageToBase64 (
  dataTransfer: DataTransfer,
  cropToSquare: boolean = false,
  compressSize?: number,
  maxFileSizeMB?: number,
) {
  // ...
}

Vue.js component:

import DragNDropLoader from "@sergtyapkin/images-uploader/vue"

Usage:

Component has a <slot> place inside to insert the elements on which it must works. Example:

<DragNDropLoader @load="[[loadOutImageToServer]]"
                 @error="alert"
                 :crop-to-square="false"
                 :compress-size="512"
>
  <img class="avatar" :src="[[OurUserAvatarFromVariable]]" alt="avatar">
</DragNDropLoader>

Props:

| name | type | required | description | |------------------|---------|----------|----------------------------------------------------------------------------------------------------------------------------| | cropToSquare | Boolean | yes | Is results dataUrl must be a square with size of minimal image side, if null => dataUrl with the size of an original image | | compressSize | Number | yes | Size to compress the longest side in, if null => dataUrl with the size of an original image | | maxAllowedSize | Number | | Maximum allowed file size in MB | | worksOnClick | Boolean | | Is loads image by click | | worksOnDragNDrop | Boolean | | Is loads image by drag and drop into elements inside <slot> | | disabled | Boolean | | Is component disabled (not reacts on user events) |

Events:

| name | value | description | |----------------|--------|-----------------------------------------------------------| | load | String | Base64 dataURL of gotten image | | error | String | Description of error if loading not finished successfully |