Git Product home page Git Product logo

image-thumbnail's Introduction

Hi there 👋

image-thumbnail's People

Contributors

dependabot[bot] avatar emmo00 avatar kasbah avatar kylebjordahl avatar leibowitz avatar mkdotcom avatar mwkldeveloper avatar naoki-tomita avatar onildoaguiar avatar segurvita avatar sergeypavlikhin avatar shahog avatar yago-ferrer avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

image-thumbnail's Issues

Possibility to keep aspect ratio

Dear Onildo (@onildoaguiar),

Thanks for sharing this node!
I was wondering if it is possible to maintain the aspect ratio when resizing?
So only specifying the width, but not the height.

Kind regards,
Bart Butenaers

cant not install library in windows 10

Hello. I try with npm i image-thumbnail and give me this error: (node version 16 and npm 7.10.0)
npm WARN deprecated [email protected]: Critical security vulnerability fixed in v0.21.1. For more information, see axios/axios#3410
npm ERR! code 1
npm ERR! path D:\work\dashboard\w-home-api\node_modules\image-thumbnail\node_modules\sharp
npm ERR! command failed
npm ERR! command C:\Windows\system32\cmd.exe /d /s /c (node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)
npm ERR! info sharp Using cached C:\Users\user\AppData\Local\npm-cache_libvips\libvips-8.9.1-win32-x64.tar.gz
npm ERR! info sharp Creating D:\work\dashboard\w-home-api\node_modules\image-thumbnail\node_modules\sharp\build\Release
npm ERR! info sharp Copying DLLs from D:\work\dashboard\w-home-api\node_modules\image-thumbnail\node_modules\sharp\vendor\lib to D:\work\dashboard\w-home-api\node_modules\image-thumbnail\node_modules\sharp\build\Release
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp info find Python using Python version 3.9.4 found at "C:\Users\user\AppData\Local\Programs\Python\Python39\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack at VisualStudioFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
npm ERR! gyp ERR! stack at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16
npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
npm ERR! gyp ERR! stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
npm ERR! gyp ERR! stack at ChildProcess.exithandler (node:child_process:333:5)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:365:28)
npm ERR! gyp ERR! stack at maybeClose (node:internal/child_process:1067:16)
npm ERR! gyp ERR! System Windows_NT 10.0.19041
npm ERR! gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd D:\work\dashboard\w-home-api\node_modules\image-thumbnail\node_modules\sharp
npm ERR! gyp ERR! node -v v16.0.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\user\AppData\Local\npm-cache_logs\2021-04-29T01_39_07_080Z-debug.log

Segfault with Libvips

Hi I am using this with Electron.

I am generating a base64 thumbnail as a gallery view with 100 images per page. (thumbnails are generated when page is accessed).
here is an example on how I am calling the function
async function generate(target){ let thumbnailOptions = { percentage: 25, responseType: 'base64', jpegOptions: 100, failOnError: false } let thumbnail = await imageThumbnail(${target}, thumbnailOptions); return thumbnai }
I have not been able to identify the exact cause, but the segfault happens when the thumbnails are being rendered and it is reporting a segfault within dmesg.

It originally happened when I specified the width as a static size as opposed to a percentage, following the change to percentage that cleared up. Now I think it is happening maybe on larger files, files above 100KB.

The dmesg log is not to helpful
electron[2309168]: segfault at 42c80010 ip 00007fc260638a31 sp 00007fff823d2cf0 error 6 in libvips-cpp.so.42[7fc25faf9000+c9e000]

Thanks heaps for the module though it is frickin awesome.

× TypeError: sharp.format is not a function

I am trying to generate thumbnail for images retrieved from a s3 storage.

const imageThumbnail = require('image-thumbnail');
let options = { width: 100, height: 100, jpegOptions : { force:true, quality:80 } }
imageThumbnail(menuItems[idx].menuPicURL, options) //options
.then(thumbnail => { console.log(thumbnail) })
.catch(err => console.error(err));

But I'm always getting this error: sharp.format is not a function
I also installed dependencies on my own - sharp, axios, image-size and validator
But nothing works...

See screenshot:

image

Error when I try to install de package

Hello, I have a error when I try to make a npm install.
In my package.json I have "image-thumbnail": "^1.0.10", declared.

The error is when the script tries to install sharp.

`npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `(node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)`       
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.`
`The '&&' token is not a valid instruction separator in this version.
En línea: 1 Carácter: 48
+ (node install/libvips && node install/dll-copy && prebuild-install -- ...`

Node version 12.16.1
OS: Windows

Force | Detect dimensions

Thanks for your module, however may I suggest you don't force dimensions as Sharp does get it well and sizeOf cant get it well on my buffer source ?
I modified your code in getDimensions to :

 if (typeof dimensions.width != 'undefined' || typeof dimensions.height != 'undefined') {
        return { width: dimensions.width, height: dimensions.height };
    }

Cheers 👍

Sharp Error using imagethumbnail in typescript?

Hi Id like to use this in an Angular application, but having trouble figuring out how.

I can get hold of a file object using the input element's "file" type, but that gives me a file reference not a path. And the stream it produces doesn't seem compatible with imageThumgnail

Here's what I tried. On my webpage I have the following:

<div>Image thumbnail: <input type="file" (change)="makeThumbnail($event)"></div>

Because I can't get the full path in the browser, in my angular component I tried this:

  async makeThumbnail(evt : Event) {
    let target : HTMLInputElement = evt.target as HTMLInputElement;
    let file : File = target.files[0];
    let stream = file.stream()
    let buffer = await stream.getReader().read();
    let thumbnail = await imageThumbnail(buffer);
    console.log(thumbnail);     
  }

But that won't compile. How to do this properly?

Add svg support

Currently SVGs don't process correctly. At least converting them to jpeg would be a nice feature.

Typo: README.md

The third line of the README.md file says By default the thumbnail's file format will be the same than the source file. instead of By default the thumbnail's file format will be the same AS the source file.

Does the Package work in serverless environment ?

Hi,

I installed the package on a serverless environment and getting the following error at runtime.
Could you please advise if this would work ?

Thank You.

> error: 
failed to execute source for 'node_modules/image-thumbnail/index.js': FunctionError: failed to execute source for 'node_modules/image-thumbnail/src/index.js': FunctionError: failed to execute source for 'node_modules/sharp/lib/index.js': FunctionError: failed to execute source for 'node_modules/sharp/lib/constructor.js': Error: 
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp.node'

- Remove the "node_modules/sharp" directory then run
  "npm install --ignore-scripts=false --verbose sharp" and look for errors
- Consult the installation documentation at https://sharp.pixelplumbing.com/install
- Search for this error at https://github.com/lovell/sharp/issues

	at node_modules/sharp/lib/constructor.js:39:9(140)

	at require (native)
	at node_modules/sharp/lib/index.js:11:21(15)

	at require (native)
	at node_modules/image-thumbnail/src/index.js:25:21(38)

	at require (native)
	at node_modules/image-thumbnail/index.js:11:26(15)


Error: Cannot find module 'sharp'

install the package by npm i image-thumbnail
import the lib by const imageThumbnail = require("image-thumbnail");

get error:
TypeError: sharp.format is not a function
(anonymous function)
node_modules/sharp/lib/constructor.js:254
251 | * @returns {Object}
252 | */
253 |

254 | Sharp.format = sharp.format();
255 | /**
256 | * An Object containing the version numbers of libvips and its dependencies.
257 | * @member

Error: ENOENT: no such file or directory, open 'image-thumbnail'

I am trying the following code in the README.

const imageThumbnail = require('image-thumbnail');

imageThumbnail('image-thumbnail')
    .then(thumbnail => { console.log(thumbnail) })
    .catch(err => console.error(err));

However, I got the following error:

Error: ENOENT: no such file or directory, open 'image-thumbnail'
    at module.exports (xxx\node_modules\image-thumbnail\src\index.js:107:15)

I think imageThumbnail('image-thumbnail') should be imageThumbnail('resources/images/dog.jpg')

VipsJpeg issue on some images

Getting this when trying to run on a JPEG from a Samsung S8 (SM-G950F):

VipsJpeg: Invalid SOS parameters for sequential JPEG
VipsJpeg: out of order read at line 0

Probably linked to lovell/sharp#1578

Error: 'linux-x64' binaries cannot be used on the 'linuxmusl-x64' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the 'linuxmusl-x64' platform.

node version
v16.4.2

Error Message
/usr/app/node_modules/sharp/lib/libvips.js:82
throw new Error('${vendorPlatformId}' binaries cannot be used on the '${currentPlatformId}' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the '${currentPlatformId}' platform.);
^

Error: 'linux-x64' binaries cannot be used on the 'linuxmusl-x64' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the 'linuxmusl-x64' platform.
at Object.hasVendoredLibvips (/usr/app/node_modules/sharp/lib/libvips.js:82:13)
at Object. (/usr/app/node_modules/sharp/lib/constructor.js:7:22)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:816:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object. (/usr/app/node_modules/sharp/lib/index.js:3:15)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:816:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object. (/usr/app/node_modules/image-thumbnail/src/index.js:6:15)

스크린샷, 2021-09-30 00-38-57

.bmp (Bitmap) image file type support

I receive this error when trying to generate a bmp thumbnail. png's work fine.

let options = {percentage: 5};
const thumbnail = await imageThumbnail(req.body.imagePath + '/' + req.body.filename, options);

[0] Error: Input buffer contains unsupported image format at module.exports (....../ImageLabeller/node_modules/image-thumbnail/src/index.js:107:15)

npm module not working

I've installed the package using
npm install thumbnail
but when I try to require it, node couldn't resolve it.
Looking the node_modules folder I realized the index.js file is inside the src/ folder. That's why node can't find it.
Perhaps its an issue with the npm package.

Support for Apple Silicon => update sharp

Hey there,

thanks for all the work. The current version is depending on sharp 0.28, which is not supporting Apple M1 Chips. It would be great if you could update in on a version >= v0.29.0.

Thanks

Allow users to specify object-position

Sharp allows position to be specified

sharp.position: top, right top, right, right bottom, bottom, left bottom, left, left top.

This is very useful and should also be allowed by image-thumbnail

Image thumbnail sharp library cause some fail

Hello,

I just update library to the newest one and I'm getting fail related to I think an older version of "sharp": "^0.19.0" library. Is it possible to update that library and release another version of image-thumbnail?

Please update package dependencies.

Installation via Azure Pipelines throws errors.
Updating dependencies fixes the errors. (sharp)

24.20 npm notice 
24.21 npm ERR! code 1
24.21 npm ERR! path /home/node/app/node_modules/sharp
24.21 npm ERR! command failed
24.22 npm ERR! command sh -c (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
24.22 npm ERR! sharp: Please see https://sharp.pixelplumbing.com/install for required dependencies
24.22 npm ERR! sharp: Installation error: Invalid Version: 1.2.4_git20230717

Error: Attempt to access memory outside buffer bounds

Hello,

I am writing a media server using express and I need to generate thumbnails when a file is uploaded. I am only working with jpegs at the moment.

app.post('/media', (req, res) => {
  let name = req.get('File-Name')
  let ext = req.get('File-Extension')
  let buffer = Buffer.from(req.body)

  fs.mkdir(__dirname + `/media/${name}/`, (err) => {
    if (err.code === 'EEXIST') {
      console.log('Please don\'t write over things.')
    } else {
      throw err
    }

    fs.writeFile(__dirname + `/media/${name}/${name}.${ext}`, buffer, (err) => {
      if (err) {throw err}
      imageThumbnail(`./media/${name}/${name}.${ext}`)
        .then(thumb=>{console.log(thumbnail)})
        .catch(err=>console.log(err))
      res.send('seems ok')
    })

  })
})

I have the same error if I call imageThumbnail(__dirname + `/media/${name}/${name}.${ext}`)

Perhaps I'm doing something wrong? Thank you.

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.