Imagine icon indicating copy to clipboard operation
Imagine copied to clipboard

Resize Image Dimensions??

Open rpelletierrefocus opened this issue 5 years ago • 4 comments

I have just discovered there does not appear to be a way to resize the dimensions of an image? Where might I find the best place to change this? I am just going to statically set it for now and add menus/functions later.

rpelletierrefocus avatar Feb 27 '20 15:02 rpelletierrefocus

To be more specific, I am just trying to reduce the dimensions by a percentage

rpelletierrefocus avatar Feb 27 '20 16:02 rpelletierrefocus

So, on line 29 of index.ts I added '-resize 50%' which results in the code below. I am wokring with a JPEG. This does not seem to work, so I am missing something else down the line.

export const mozjpeg: IOptimizeMethod = (
  input,
  output,
  options,
) => {
  const { quality = 70 } = options

  const spawnArgs = [
    '-quality',
    quality.toString(),
    '-resize 50%',
    '-outfile',
    output,
    input,
  ]

  log.info('spawn', bins.mozjpeg, spawnArgs)

  return spawn(bins.mozjpeg, spawnArgs, {
    capture: [ 'stdout', 'stderr' ],
    env: createEnv(),
  }).catch(e => {
    throw new Error(e.message + '\n' + e.stderr)
  })
}

rpelletierrefocus avatar Feb 27 '20 16:02 rpelletierrefocus

Just realized this method is not uing imagemagick (I had assuemed), but mozjpeg, whcih I am not familiar with, but does not seem to have a dimension (resize) option.

rpelletierrefocus avatar Feb 27 '20 16:02 rpelletierrefocus

You could use imagemagick to resize then use mozjpeg to compress.

await spawn(bins.imagemagick) // input -> temp
await spawn(bins.mozjpeg) // temp -> output

meowtec avatar Feb 29 '20 14:02 meowtec