Giter Site home page Giter Site logo

django-webp-converter's People

Contributors

tmiller02 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

django-webp-converter's Issues

static_webp tag creates WebPImage duplicates

Sometimes this can create duplications and cause MultipleObjectsReturned error:

if not webp_image_url:
    webp_image, _ = WebPImage.objects.get_or_create(
        static_path=static_path, quality=quality)

I don't think the uniqueness constraint works here because quality is nullable (see ticket):

unique_together = (('static_path', 'quality'),)

So maybe alter the field to:

quality = models.PositiveIntegerField(default=80)

OSError at /

I'm getting an error, when using:
<img class="img" style="width: auto; height: 180px;" src="{% static_webp 'media/thumbnails/92a59b5cd391e6b5b1e859440179a8e92e512265.png' %}" alt="{{ post.title }}">

I'm loading the converter using: {% load webp_converter %}

How to fix this?

Request Method: GET
http://127.0.0.1:8000/
2.2.9
OSError
Can't find static image.
C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\webp_converter\models.py in image_absolute_path, line 27
C:\Users\User\AppData\Local\Programs\Python\Python37\python.exe
3.7.0
['C:\Users\User\Desktop\ModForest\modsForMinecraft', 'C:\Users\User\AppData\Local\Programs\Python\Python37\python37.zip', 'C:\Users\User\AppData\Local\Programs\Python\Python37\DLLs', 'C:\Users\User\AppData\Local\Programs\Python\Python37\lib', 'C:\Users\User\AppData\Local\Programs\Python\Python37', 'C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages']
Sat, 8 Feb 2020 14:25:32 +0000

Best way to deal with cache?

Would a cron job be the right way to delete the cache?

I see the docs have clear_webp_cache --no-input

(using virtualenv):

sudo crontab -e
* * * * * /usr/bin/env bash -c 'cd /home/user/project/ && source /home/user/project/bin/activate && python3 manage.py clear_webp_cache --no-input' > /dev/null 2>&1

What would be the best way to deal with the cache? I see there being problems with the hardware possibly failing unless absolutely nothing is done. Especially if there are lots of page views on your website every second and there are a lot of images being converted.

Can you / someone provide some additional examples with handling the caching problems / running some tests showing the results of overloading the cache or maybe there is a better way to not even needing the caching at all? Using the database has the same sort of problem.

Maybe use the session?

Also, what about rate limiting?

Maybe update the docs with maybe that cron job or other details besides just running clear_webp_cache --no-input

Apple Safari / IOS Handling

Is there a way either with this package or in general with django to deal with IOS & safari since it does not support webp as of today? If not, adding an if statement to the template saying if ios/safari then use jpeg/png otherwise use webp. Does this package currently automatically determine if webp is supported on a browser and not use it if it isn't? Otherwise open to other ideas.

https://caniuse.com/#feat=webp

Add Support For Database models.ImageField images stored in /media

https://pypi.org/project/django-webp/ does not seem actively maintained but this django-webp-converter is. Why not include the same type of functionality as that django-webp but update it to newer python3 and django 3?

Issue #3 expressed this problem and it would be nice to support images stored in /media that originate from models.py ImageField.

In my project, I want to be able to do this because Facebook Opengraph and Twitter cards metadata requires filetypes that are not webp. I want my website output to show the webp images while Facebook and Twitter are given the jpeg/png images.

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

thumbnail = models.ImageField(blank=True, null=True, max_length=255)

Do something like:

<img src="{% webp object.thumbnail.url %}" />
<img src="/media/test.webp" />

Problem installing project in new server

Hi Tom, I trying to install the project via pip install but I get the next warning:

(app:3.7)[rt@zeus sanfrancisco]$ pip install django-webp-converter
Collecting django-webp-converter
Using cached django-webp-converter-0.3.0.tar.gz (4.5 kB)
WARNING: Generating metadata for package django-webp-converter produced metadata for project name unknown. Fix your #egg=django-webp-converter fragments.
Requirement already satisfied (use --upgrade to upgrade): unknown from https://files.pythonhosted.org/packages/57/e1/020a47cbcbd39f1e6269e45a05693edccd7673ec850cb059cab633082be8/django-webp-converter-0.3.0.tar.gz#sha256=45bfc8cd1abc65497b7fd46678b63187346dc0d0c1512a36f79519014442e569 in /home/rt/virtualenv/app/3.7/lib/python3.7/site-packages
Building wheels for collected packages: unknown, unknown
Building wheel for unknown (setup.py) ... done
Created wheel for unknown: filename=UNKNOWN-0.0.0-py3-none-any.whl size=1560 sha256=cf0b2e25b01333fc860b7f40c7f44bfb2bfabf03c87083f88e87140a6109a595
Stored in directory: /home/rt/.cache/pip/wheels/46/8f/67/7768e2143a42554a32ee2c6e53bc7de3d2bae010ab51738c3d
Building wheel for unknown (setup.py) ... done
Created wheel for unknown: filename=UNKNOWN-0.0.0-py3-none-any.whl size=1560 sha256=cf0b2e25b01333fc860b7f40c7f44bfb2bfabf03c87083f88e87140a6109a595
Stored in directory: /tmp/pip-ephem-wheel-cache-xrnz2pof/wheels/75/fe/6f/8f1051f59fa32d5a78f860fa757bff27351523fd628c01a94e
Successfully built unknown unknown

So trying use --upgrade as the pip tells me that requirement is already satisfied.

(app:3.7)[rt@zeus sanfrancisco]$ pip install django-webp-converter --upgrade
Collecting django-webp-converter
Using cached django-webp-converter-0.3.0.tar.gz (4.5 kB)
WARNING: Generating metadata for package django-webp-converter produced metadata for project name unknown. Fix your #egg=django-webp-converter fragments.
Building wheels for collected packages: unknown, unknown
Building wheel for unknown (setup.py) ... done
Created wheel for unknown: filename=UNKNOWN-0.0.0-py3-none-any.whl size=1560 sha256=4c4d733abb98d3394acb9d44c5cdcc146d2078cf445f4109bfe6f5d1b6b09b6b
Stored in directory: /home/rt/.cache/pip/wheels/46/8f/67/7768e2143a42554a32ee2c6e53bc7de3d2bae010ab51738c3d
Building wheel for unknown (setup.py) ... done
Created wheel for unknown: filename=UNKNOWN-0.0.0-py3-none-any.whl size=1560 sha256=4c4d733abb98d3394acb9d44c5cdcc146d2078cf445f4109bfe6f5d1b6b09b6b
Stored in directory: /tmp/pip-ephem-wheel-cache-6yay5d4u/wheels/75/fe/6f/8f1051f59fa32d5a78f860fa757bff27351523fd628c01a94e
Successfully built unknown unknown
Installing collected packages: unknown
Attempting uninstall: unknown
Found existing installation: UNKNOWN 0.0.0
Uninstalling UNKNOWN-0.0.0:
Successfully uninstalled UNKNOWN-0.0.0
Successfully installed unknown-0.0.0

Finally my pip freeze show:

six==1.14.0
sqlparse==0.3.1
static3==0.7.0
UNKNOWN==0.0.0
urllib3==1.25.9

may could be a problem collecting from repository ???

thanks for your help, as always.

OSError: Can't find static image.

Hi, I'm trying to use webp-converter in production with my website I'm using the next:

Test and run in local I've no problem, but when deploy the project to a heroku and using AWS S3 (also testing using heroku local on my machine) I get an Error.

I follow the describes in Documentation creating by yourself, Django Docs and it's important to remark that before trying webp-converter everything work well, even in mobile devices everything work well. What could be happen to my code ?

Thanks for your support, Next the error that I give:

4:21:11 PM web.1 | [2020-04-20 16:21:11 -0400] [36337] [CRITICAL] WORKER TIMEOUT (pid:38015)
4:21:11 PM web.1 | [2020-04-20 16:21:11 -0400] [38015] [INFO] Worker exiting (pid: 38015)
4:21:11 PM web.1 | [2020-04-20 16:21:11 -0400] [38289] [INFO] Booting worker with pid: 38289
4:28:25 PM web.1 | ERROR:django.request:Internal Server Error: /
4:28:25 PM web.1 | Traceback (most recent call last):
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
4:28:25 PM web.1 | response = get_response(request)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
4:28:25 PM web.1 | response = self.process_exception_by_middleware(e, request)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
4:28:25 PM web.1 | response = wrapped_callback(request, *callback_args, **callback_kwargs)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
4:28:25 PM web.1 | response = view_func(request, *args, **kwargs)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/rtsf/apps/website/views.py", line 81, in index
4:28:25 PM web.1 | return render(request, 'website/index.html', locals())
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/shortcuts.py", line 19, in render
4:28:25 PM web.1 | content = loader.render_to_string(template_name, context, request, using=using)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/template/loader.py", line 62, in render_to_string
4:28:25 PM web.1 | return template.render(context, request)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/template/backends/django.py", line 61, in render
4:28:25 PM web.1 | return self.template.render(context)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/template/base.py", line 171, in render
4:28:25 PM web.1 | return self._render(context)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
4:28:25 PM web.1 | return self.nodelist.render(context)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/template/base.py", line 936, in render
4:28:25 PM web.1 | bit = node.render_annotated(context)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
4:28:25 PM web.1 | return self.render(context)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/template/loader_tags.py", line 150, in render
4:28:25 PM web.1 | return compiled_parent._render(context)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/template/base.py", line 163, in _render
4:28:25 PM web.1 | return self.nodelist.render(context)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/template/base.py", line 936, in render
4:28:25 PM web.1 | bit = node.render_annotated(context)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/template/base.py", line 903, in render_annotated
4:28:25 PM web.1 | return self.render(context)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/django/template/library.py", line 192, in render
4:28:25 PM web.1 | output = self.func(*resolved_args, **resolved_kwargs)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/webp_converter/templatetags/webp_converter.py", line 28, in static_webp
4:28:25 PM web.1 | webp_image.save_image()
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/webp_converter/models.py", line 52, in save_image
4:28:25 PM web.1 | image = Image.open(self.image_absolute_path)
4:28:25 PM web.1 | File "/Users/MarioPlaza/Documents/Nbeta/venvs3/rtsf-3/lib/python3.7/site-packages/webp_converter/models.py", line 27, in image_absolute_path
4:28:25 PM web.1 | raise IOError("Can't find static image.")
4:28:25 PM web.1 | OSError: Can't find static image.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.