meowtec / Imagine

🖼️ PNG/JPEG optimization app for macOS, Windows and Linux.
MIT License
3.69k stars 278 forks source link

Resize Image Dimensions?? #63

Open rpelletierrefocus opened 4 years ago

rpelletierrefocus commented 4 years ago

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 commented 4 years ago

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

rpelletierrefocus commented 4 years ago

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 commented 4 years ago

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.

meowtec commented 4 years ago

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

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