sebinbenjamin / image-res-generator

A versatile tool for generating icons and splash screens for web and mobile projects. Supports Angular, Ionic, PWA, and more, with seamless SVG and PNG resource generation.
GNU General Public License v3.0
8 stars 5 forks source link

crop behavior request #86

Open ccckblaze opened 4 years ago

ccckblaze commented 4 years ago

i'd like the old flavor of crgen, the image crop which just based on the px, not resize the original image

so i did a patch for current version

const transformSplash = (definition) => {
const image = imageObj.splash;
const { width } = definition;
const { height } = definition;
const outputFilePath = path.join(platformPath, definition.name);
const outDir = path.dirname(outputFilePath);
return fs.ensureDir(outDir).then(() => image
.extract({left: parseInt((image.meta.width - width) / 2), top: parseInt((image.meta.height - height) / 2) , width, height})
.toFile(outputFilePath));
};``

.extract({left: parseInt((image.meta.width - width) / 2), top: parseInt((image.meta.height - height) / 2) , width, height})

instead of

.crop(sharp.strategy.entropy)

can you give a build-in command line switch for this

like irgen --extract or something else

please ^ ^

ccckblaze commented 4 years ago

@sebinbenjamin can you help me out, please

sebinbenjamin commented 4 years ago

Sure. Please get me a screenshot/image of the expected behavior, to make sure I understand you correctly.

sebinbenjamin commented 4 years ago

i'd like the old flavor of crgen, the image crop which just based on the px, not resize the original image

so i did a patch for current version

const transformSplash = (definition) => { const image = imageObj.splash; const { width } = definition; const { height } = definition; const outputFilePath = path.join(platformPath, definition.name); const outDir = path.dirname(outputFilePath); return fs.ensureDir(outDir).then(() => image .extract({left: parseInt((image.meta.width - width) / 2), top: parseInt((image.meta.height - height) / 2) , width, height}) .toFile(outputFilePath)); };``

.extract({left: parseInt((image.meta.width - width) / 2), top: parseInt((image.meta.height - height) / 2) , width, height})

instead of

.crop(sharp.strategy.entropy)

can you give a build-in command line switch for this

like irgen --extract or something else

please ^ ^

.crop(sharp.strategy.entropy) was changed to image.resize({ width, height, position: 'centre' }) some time ago. Please let me know if your issue is fixed.

ccckblaze commented 4 years ago

my bad... i installed from npm version 0.62, it seems an old deprecated version, now it works perfectly! thanks @sebinbenjamin , when will you tag this version and upload to npm?

ccckblaze commented 4 years ago

the image now crops centre, but there is still a problem, irgen works different from crgen, i want it "crop" not "resized"

base splash image

now image

hoped image

so the image will not lose detail

sebinbenjamin commented 4 years ago

I'm working on a solution, although you should try to use a proper splash base to start with. Ideally, the splash screen's artwork should roughly fit/cover a square (1200×1200px out of 2732x2732px) at the centre of the image. You can use this template provided by the Ionic team.

Make sure that the logo fits in the orange square at the centre. A minimum content size covering at least half of the orange square makes sure that the output splash does not lose much detail.

splash