Skip to content

Commit

Permalink
Fix: Avoid generating thumbnails of images that are still being extra…
Browse files Browse the repository at this point in the history
…cted (Extractions with 7-Zip)
  • Loading branch information
ollm committed Dec 11, 2024
1 parent 87ac55c commit c415b3f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Save image not saving the correct page in manga mode [`b14a26e`](https://github.com/ollm/OpenComic/commit/b14a26eacdc77d37cdeb578fc203438058c7c5e2)
- Sometimes right click on reading fails [`b14a26e`](https://github.com/ollm/OpenComic/commit/1a8e145a997c67494e1a6c70c5f73acee7720000)
- Avoid generating thumbnails of images that are still being extracted (Extractions with 7-Zip)

## [v1.3.1](https://github.com/ollm/OpenComic/releases/tag/v1.3.1) (05-10-2024)

Expand Down
2 changes: 1 addition & 1 deletion TRANSLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ OpenComic has translations into 17 languages.

[ru.json](https://github.com/ollm/OpenComic/blob/master/languages/ru.json)

`27.3% | Remain 309 | Translated 116`
`100% | Remain 0 | Translated 425`

<a href="https://github.com/ollm/OpenComic/blob/master/languages/ru.json"><img src="https://raw.githubusercontent.com/ollm/OpenComic/master/images/translated/ru.svg" /></a>

Expand Down
2 changes: 1 addition & 1 deletion images/translated.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion images/translated/ru.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
96 changes: 59 additions & 37 deletions scripts/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,82 @@ async function resize(fromImage, toImage, config = {})
if(/*inArray(extension, imageExtensions.ico)/* || */inArray(extension, imageExtensions.ico)) // Unsupported images format for resize
return reject({});

sharp(fromImage, {failOn: 'none'}).flatten({background: {r: 255, g: 255, b: 255}}).jpeg({quality: config.quality}).resize(config).toFile(toImage, async function(error) {

if(error && /unsupported image format/iu.test(error?.message || ''))
{
if(!imageMagick) imageMagick = require('gm').subClass({imageMagick: true});
_resize(fromImage, toImage, config, resolve, reject);

imageMagick(fromImage).resize(config.width, null).quality(config.quality).noProfile().write(toImage, function(error){
});
}

if(error)
{
if(!graphicsMagick) graphicsMagick = require('gm').subClass({imageMagick: false});
async function _resize(fromImage, toImage, config = {}, resolve, reject, deep = 0)
{
let options = {}

graphicsMagick(fromImage).resize(config.width, null).quality(config.quality).noProfile().write(toImage, async function(error){
if(deep > 3)
options = {failOn: 'none'};

if(error)
{
if(jimp === false) jimp = require('jimp').Jimp;
sharp(fromImage, options).flatten({background: {r: 255, g: 255, b: 255}}).jpeg({quality: config.quality}).resize(config).toFile(toImage, async function(error) {

try
{
const jimpImage = await jimp.read(fromImage);
await jimpImage.resize({w: config.width}).write(toImage, {quality: config.quality});
if(error && /unsupported image format/iu.test(error?.message || ''))
{
if(!imageMagick) imageMagick = require('gm').subClass({imageMagick: true});

resolve(toImage);
}
catch(error)
{
reject(error);
}
}
else
imageMagick(fromImage).resize(config.width, null).quality(config.quality).noProfile().write(toImage, function(error){

if(error)
{
if(!graphicsMagick) graphicsMagick = require('gm').subClass({imageMagick: false});

graphicsMagick(fromImage).resize(config.width, null).quality(config.quality).noProfile().write(toImage, async function(error){

if(error)
{
if(jimp === false) jimp = require('jimp').Jimp;

try
{
const jimpImage = await jimp.read(fromImage);
await jimpImage.resize({w: config.width}).write(toImage, {quality: config.quality});

resolve(toImage);
}
});
catch(error)
{
reject(error);
}
}
else
{
resolve(toImage);
}
});

}
else
{
resolve(toImage);
}
});
}
else if(error)
}
else
{
resolve(toImage);
}
});
}
else if(error)
{
if(deep > 3)
{
console.error(fromImage, error);
reject(error);
}
else
{
resolve(toImage);
}
});
deep++;

console.error('Error: '+(deep > 3 ? 'Trying once more' : 'Trying again')+' in '+(100 * deep)+'ms'+(deep > 3 ? ' with failOn: none' : '')+' | '+fromImage, error);

await app.sleep(100 * deep);
_resize(fromImage, toImage, config, resolve, reject, deep);
}
}
else
{
resolve(toImage);
}
});
}

Expand Down
2 changes: 1 addition & 1 deletion themes/material-design/actions.css
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@
width: 50% !important;
left: 50% !important;
max-width: 640px;
transform: translateY(-50%) translateX(-50%) !important;
transform: translateY(-50%) translateX(-50%) !important; /*! Keep this line */
transform: translateY(round(-50%, 1px)) translateX(round(-50%, 1px)) !important;
padding: 0px;
border-radius: 24px;
Expand Down

0 comments on commit c415b3f

Please sign in to comment.