Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for thumbnailing SVG images #560

Merged
merged 34 commits into from
Nov 3, 2021
Merged

Add support for thumbnailing SVG images #560

merged 34 commits into from
Nov 3, 2021

Conversation

jrief
Copy link
Collaborator

@jrief jrief commented Nov 23, 2020

Add support for thumbnailing SVG images.

Of course it doesn't make sense to thumbnail SVG images, because being in vector format they can scale to any size without any quality of loss. However, users of easy-thumbnails may want to upload and use SVG images just as if they would be PNG, GIF or JPEG. They don't necessarily care about the format and definitely don't want to convert them to a pixel based format. What they want is to reuse their templates with the templatetag thumbnail and scale and crop the images to whatever their <img src="..." width="..." height="..."> has been prepared for.

This is done by adding an emulation layer named VIL, which aims to be compatible with PIL. All thumbnailing operations, such as scaling and cropping behave like pixel based images. The final filesize of such thumbnailed SVG images doesn't of course change, but their width/height and bounding box may be adjusted to reflect the desired size of the thumbnailed image.

Jacob Rief and others added 25 commits September 28, 2020 08:02
…into svg-support

# Conflicts:
#	CHANGES.rst
#	easy_thumbnails/signals.py
#	tox.ini
# Conflicts:
#	CHANGES.rst
#	easy_thumbnails/__init__.py
@artragis
Copy link

artragis commented Mar 7, 2021

Are there any news about this PR?

@jrief
Copy link
Collaborator Author

jrief commented Mar 7, 2021

easy-thumbnails already supports SVG images. Please try using this version: https://pypi.org/project/easy-thumbnails/2.8rc0/

If you use django-filer there is a release which uses these new features: https://pypi.org/project/django-filer/2.1rc3/

I never got any feedback on this new feature, therefore I forgot to create a production release of the above packages.

@artragis
Copy link

artragis commented Mar 7, 2021

Ok, we will test it when we have time and give you feedback so that you can have production package.

@artragis
Copy link

artragis commented Mar 8, 2021

Ok, I manage to integrate some things but failed on others

  • need to change the django ImageField validator
  • I did not manage to have the crop&co experience for svg, I was forced to add this format to THUMBNAIL_PRESERVE_EXTENSIONS

@strugo
Copy link

strugo commented Mar 21, 2021

Hello. I understand correctly that now it is not possible to load svg or bitmap in ThumbnailerImageField. Only raster is supported.

Or I didn’t understand something. I'm watching version 2.8rc0

Perhaps a different workflow is expected?

@drc0
Copy link

drc0 commented Jun 3, 2021

@jrief can you please tell how to test this rc and accept svg files through ThumbnailerImageField? installing easy-thumbnails==2.8rc0
and putting a ThumbnailerImageField on a model doesn't let me accept svg files and the admin rises an error telling me that isn't a supported image type. thanks
(as a side note probably the workflow could be to use ThumbnailerField directly)

@jaap3
Copy link
Contributor

jaap3 commented Jun 9, 2021

@jrief have you considered releasing VIL as a standalone package and then adding it as a dependency to easy-thumbnails? It seems like a more generally useful project that shouldn't be hidden inside a submodule of easy_thumbnails.

This PR also contains a number of unrelated changes, which makes it harder to review. Is this because you decided to use this branch as a base for the pre-release? I believe it's bad form to pre-release an unmerged (and unreviewed) branch, I would have expected at least some involvement of the original project owner (@SmileyChris).

@jrief
Copy link
Collaborator Author

jrief commented Jun 9, 2021

have you considered releasing VIL as a standalone package and then adding it as a dependency to easy-thumbnails?

Actually no. Reason is, that "VIL" just mimics the behaviour of PIL without transforming the images SVG themselves. Well sort of, by changing the the coordinates inside the SVG viewbox, one can "crop" an SVG image. But I don't see any usage of that mimicking behaviour outside easy-thumbnails.

This PR also contains a number of unrelated changes, which makes it harder to review.

A requirement of the organization I am working for was to support SVG images by django-filer. With the changes in this PR, I came up with a working solution. Therefore I needed a pre-release. I asked a few people to review django-filer together with this version of easy-thumbnails, but got little feedback.

I heavily welcome you to review the changes I have made, so that I can release SVG support officially. The best way of doing this is via https://pypi.org/project/django-filer/2.1rc3/

Apparently one has to release an official version, before people start yelling, that you broke something which used to work for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants