Skip to content

Improve image handling#2041

Open
BentiGorlich wants to merge 8 commits intomainfrom
new/image-handling-improvements
Open

Improve image handling#2041
BentiGorlich wants to merge 8 commits intomainfrom
new/image-handling-improvements

Conversation

@BentiGorlich
Copy link
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
unlink($tempPath);
}

return $compressed && $copied;
Copy link
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
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
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)

- 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 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
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
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
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

*/
public function findOldRemoteMediaPaginated(int $olderThanDays, int $limit = 10000): Pagerfanta
{
$query = $this->createQueryBuilder('i')
Copy link
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 from 22fcd7a to 34d6a19 Compare March 18, 2026 09:13
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