Skip to content

Improve image handling#2041

Merged
BentiGorlich merged 11 commits intomainfrom
new/image-handling-improvements
Mar 25, 2026
Merged

Improve image handling#2041
BentiGorlich merged 11 commits intomainfrom
new/image-handling-improvements

Conversation

@BentiGorlich
Copy link
Copy Markdown
Member

  • add created_at and downloaded_at timestamps to the image entity
  • add local_size and original_size properties to the image entity. Will be 0 per default and will stay like this for a while
  • explicitly pull in the imagine library already used via liip/imagine-bundle to compress images
  • new setting for the compression quality, it defaults to -1 which disables it. If enabled it will compress images to stay under the max image bytes setting
  • add command to remove cached remote images without removing the reference, that way they can be redownloaded if needed
  • redownload not-cached images when opening the thread it is attached to (if it was a comment then the thread is also the relevant thing)
  • delete all cached variants (meaning the liip/imagine filters: avatar_thumb, entry_thumb, etc.) of an image when deleting it

Closes #511

@BentiGorlich BentiGorlich self-assigned this Mar 4, 2026
@BentiGorlich BentiGorlich added enhancement New feature or request activitypub ActivityPub related issues backend Backend related issues and pull requests labels Mar 4, 2026
@BentiGorlich BentiGorlich force-pushed the new/image-handling-improvements branch from c2af8cf to 69f6e33 Compare March 4, 2026 16:58
Comment thread docs/02-admin/04-running-mbin/05-cli.md Outdated
Comment thread src/Controller/Entry/EntrySingleController.php Outdated
Comment thread src/Controller/Post/PostSingleController.php Outdated
Comment thread src/Service/ImageManager.php Outdated
Comment thread src/Service/ImageManager.php Outdated
unlink($tempPath);
}

return $compressed && $copied;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If $copied is true, then $compressed has to be true. So this && is redundant.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no it does not. The copy operation could fail, then you would not make into the if in line 130 and $copied would be false

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. My argument still holds. As $compressed && $copied can be shortened to $copied.

$compressed === false -> $copied === false === ($compressed && $copied)
$compressed === true ; <copy fails> -> $copied === false === ($compressed && $copied)
$$compressed === true ; <copy sucessful> -> $copied === true === ($compressed && $copied)

@BentiGorlich BentiGorlich force-pushed the new/image-handling-improvements branch from 69f6e33 to aa37fcb Compare March 6, 2026 08:18
@BentiGorlich BentiGorlich requested a review from blued-gear March 6, 2026 08:19
## A better user experience

Normally there is a maximum image size your users must adhere to, but if image compression is enabled,
instead of showing your user an error that the image exceeds that size, the upload goes through and the image is compressed.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if a user uploads a PNG which is over the size limit. As it can not be further compressed, will it be rejected or be stored despite being larger than allowed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should then still get rejected imo

Copy link
Copy Markdown
Member Author

@BentiGorlich BentiGorlich Mar 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything above the size limit will still be rejected

Comment thread src/Repository/ImageRepository.php Outdated
*/
public function findOldRemoteMediaPaginated(int $olderThanDays, int $limit = 10000): Pagerfanta
{
$query = $this->createQueryBuilder('i')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this variable seems to be unused

@BentiGorlich BentiGorlich force-pushed the new/image-handling-improvements branch 2 times, most recently from b5fcdd3 to 5d27f1d Compare March 21, 2026 10:40
blued-gear
blued-gear previously approved these changes Mar 23, 2026
- add `created_at` and `downloaded_at` timestamps to the image entity
- add `local_size` and `original_size` properties to the image entity. Will be 0 per default and will stay like this for a while
- explicitly pull in the `imagine` library already used via `liip/imagine-bundle` to compress images
- new setting for the compression quality, it defaults to `-1` which disables it. If enabled it will compress images to stay under the max image bytes setting
- add command to remove cached remote images without removing the reference, that way they can be redownloaded if needed
- redownload not-cached images when opening the thread it is attached to (if it was a comment then the thread is also the relevant thing)
- fix naming of the repository in both `PostSingleController` and `EntrySingleController`
- always use the highest compression for PNGs
@BentiGorlich BentiGorlich enabled auto-merge (squash) March 25, 2026 09:33
@BentiGorlich BentiGorlich merged commit 8db8783 into main Mar 25, 2026
9 checks passed
@BentiGorlich BentiGorlich deleted the new/image-handling-improvements branch March 25, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

activitypub ActivityPub related issues backend Backend related issues and pull requests enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Further Improve Handling of huge remote images

3 participants