jwagner / smartcrop.js

Content aware image cropping

Home Page:http://29a.ch/2014/04/03/smartcrop-content-aware-image-cropping

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cropped image dimensions by 30% is like 5% less size on memory

bacloud23 opened this issue · comments

commented

note: I know the main purpose of this, is to smart crop, and this is already great. Still I have another problem

Context

I want to use this amazing library for uploads in browser. I tried to grab code from testsuite and it works fine.

Unfortunately I find in most cases:

Problem

cropped size in px / original size in px

is always way less than

cropped size in mb / original size in mb

I wished smartcrop.js would let the image quality as is, in this case I think size on memory would drop relatively to the cropped size ( logically as images are raw data? ).

Thanks a lot !!

I wished size would drop relatively as smartcrop is intended also for optimizing size. that would be great !

Hi @bacloud14,

I'm not sure what you mean. smartcrop.js does not do anything to image quality nor does it do image compression - or anything else - to the image. It just gives you candidate crops. The test suite just draws on . It doesn't do image compression either.

Could you provide a bit more background on what you mean?

ok, I tried that "guitarist.jpg" file, cropped with var options = { debug: false, width: 250, height: 250 };

The result image of type 'png' with these observations:

guitarist.jpg is 427 * 640 px
canvas.png is 250 * 250 px

while
guitarist.jpg is 170KB
canvas.png is 146KB

I thought canvas.png would much less in file size.

Something near : ((250 * 250) / (427 * 640)) * 170 = 38.87 KB

Like when you take a paper, crop it with scissors, the amount of paper is always the same relatively to size.

You are really comparing apples and oranges here. PNG and JPEG compress data differently. PNG is generally a quite bad choice to compress photographs. Maybe https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types#choosing_an_image_format or https://www.freecodecamp.org/news/best-image-format-for-web-in-2019-jpeg-webp-heic-avif-41ba0c1b2789/ help you understand that a bit better.

But that really doesn't have anything to do with smartcrop. Smartcrop doesn't produce jpegs or pngs - it just gives you crops.

Probably I mistakenly change the name of the output file to PNG.
So I assume crop doesn't change extension I mean I'm sure now.
Anyway, my question was clear on why the crop size is not relative to the new size.
Anyway closing this as I seem not to be presenting the idea well. Thanks.