Giter Club home page Giter Club logo

exif-rotate-js's Introduction

exif-rotate-js ・ CircleCI

When you use input file, you can get base64 string as array without worrying about orientation of exif.

Usage

$ npm install exif-rotate-js

API

const data = await getBase64Strings(files, {maxSize, type, quality}))

Return Values

  • a promise returning array string as base64 like ["data:image/jpeg;base64,/9j/4AAQS..."]

Parameters

  • files: input target files. User can select multiple files.
  • maxSize = 720: canvas max size. When image's width is greater than height, maxSize applies to width. And vice versa.
  • type = 'image/jpeg': the mime type of the generated image. Any mime type supported by HTMLCanvasElement.toDataURL() is supported.
  • quality (optional): a number between 0 and 1 indicating the image quality to use for image formats that use lossy compression such as image/jpeg and image/webp. If this argument is anything else, the default value for image quality is used. As per the spec, the default (undefined) value will use 0.92.

Example

import { getBase64Strings } from 'exif-rotate-js';

const elem = document.getElementById('fileImage');

if (elem) {
  elem.onchange = async (e) => {
    if (!e.target) return;
    const data = await getBase64Strings(e.target.files, { maxSize: 1024 });
    console.log(data); // ["data:image/jpeg;base64,/9j/4AAQS..."] as type of Array
  };
}

exif-rotate-js's People

Contributors

dependabot[bot] avatar michellocana avatar mtjn avatar oobayly avatar renovate-bot avatar renovate[bot] avatar taro-shono avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

exif-rotate-js's Issues

Version 1.0.2 - Cannot resolve module

Importing [email protected] causes a breaking error
Module not found: Can't resolve 'exif-rotate-js/lib' in '/path/to/file/with/import

Have tried imports as:
import { getBase64Strings } from "exif-rotate-js/lib";
import { getBase64Strings } from "exif-rotate-js";

All fail. This error does not occur on [email protected]

Code sandbox example (emitting different error): https://codesandbox.io/embed/wizardly-night-df64t

Error emitted:
Could not fetch dependencies, please try again in a couple seconds: Something went wrong while packaging the dependency [email protected]: ENOENT: no such file or directory, scandir '/tmp/223538212/node_modules/exif-rotate-js/lib'

I don't understand why the package.json main field specifies lib/index.js, as there is no lib folder or index file.. But this is unchanged since version 1.0.1, so not sure why it would now cause this error.

getBase64Strings is truncating the octet-stream in Windows environments

The call const data = await getBase64Strings(files, {maxSize, type, quality})) is creating a request the ends up being truncated when running on a Windows machine:
image
image

This issue was reproduced both in Chrome and Firefox on Windows 10. Check the content truncated to 1MB:
image

Both browsers work fine when running on MacOS. Using the same file:
image

Use a large file to reproduce the issue.

Feature - Add ability to pass quality parameter

HTMLCanvasElement.toDataURL() provides the ability to specify encoder options for specifying the lossy compression quality. The TOptions interface could easily be extended to include this parameter.

I'll put a PR together for this.

I've put together a PR for this. I've opted to leave the default quality undefined, so that it uses the default behaviour of the browser's javascript engine (which I believe defaults to 0.92)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • chore(deps): update dependency eslint to v9

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/release.yml
  • actions/checkout v4
  • actions/setup-node v3
.github/workflows/test.yml
  • actions/checkout v4
  • actions/setup-node v3
npm
package.json
  • exif-js ^2.3.0
  • @babel/preset-env 7.22.20
  • @babel/preset-typescript 7.22.15
  • @types/jest 27.5.2
  • @typescript-eslint/eslint-plugin 6.6.0
  • @typescript-eslint/parser 6.6.0
  • babel-jest 27.5.1
  • eslint 8.49.0
  • eslint-config-prettier 9.0.0
  • eslint-plugin-prettier 4.2.1
  • jest 27.5.1
  • prettier 2.8.8
  • ts-jest 27.1.5
  • typescript 4.9.5

  • Check this box to trigger a request for Renovate to run again on this repository

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)

Invalid rotation image

When try to rotate the image with exif orientation code 6, a result image is distorted and has black area on the buttom.

I think the problem is at around line 36 of exif-rotate-js/src/getBase64Strings.ts

context.drawImage(image, 0, 0, width, height);

parameter width and height should swap if image is rotated

Image type option

Hey, cool lib, using it for a while and works great! :)
The only issue i found is when you want to fix the exif in a transparent image, getBase64Strings returns a jpeg data URL with black background.
Maybe we can add a type option to pass the wanted mime type, what do you think? Let me know if i can submit a PR with that feature.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.