images on django site from matplotlib - django

I am looking to have an entry form where you can enter in a server name and end up getting several png images displayed that are created from matpotlib.
I can create the form, and have the scripts written that create the image files. I am wondering what the best way to deal with the images are. Is there a way I can display the resulting png file to the browser but not save it to disk?
Want to avoid cluttering up a directory with the generated images after they are displayed the the browser. Should I just delete the image after its rendered?

response = HttpResponse(mimetype="image/png")
img.save(response, "PNG")
return response

Related

Django Weasyprint Timeout error for loading images in log

and I made a project that takes some pictures and converts them to pdf using weasyprint library. everything is alright in localhost but when I deployed it in python anywhere it generates the pdf but pictures that supposed to be in it dosent display and just the replace string of them is in the pdf please help me
Weasyprint might not be able to load the pictures. Check that the URLs you give can be accessed by Weasyprint. When in doubt, try using data URIs which don't require loading over the network.

Modify image uploaded in django 2.0 before the image is saved to disk

I have a model with a FileField for document uploads (e.g. images, pdfs, or videos). I use this line in my Document model:
storage_file_name = models.FileField('File name', upload_to=unique_file_path)
and in unique_file_path I change the name of the uploaded document to a unique file name. I find that I will be uploading some tiffs, which I need to change to jpeg or something that a browser can easily display.
I have been looking for the best way to convert the uploaded tiff file to jpeg. Is there a way to do it before the image is saved to the disk, or is the best way to use a
#receiver(models.signals.post_save, sender=Document)
and save the converted image over the saved tiff image?
At this point I am only using the admin pages and not any custom views (except by customizing the admin pages).
Thanks!
Mark

Save and uploaded image in Shiny

I´m trying to save an uploaded jpg in a Shini app, but I can´t find the way.
I upload and image correctly with Fileinput. No problem there.
I want to be able to save that image in the server to use it in the future.
How can I do this?
Thankls!!!

Upload an image with AJAX, crop portion of our choice, and save in django admin

I need to give the admin the feature of uploading an image for an ImageField using AJAX, and then crop the portion of his choice (with a predefined dimension ratio or resolution) and then save the cropped image in the database.
I tried django-image-cropping and django-ajaximage for this.
#Using django-image-cropping
from image_cropping import ImageRatioField
class Alumnus(models.Model):
photo = models.ImageField(null=True, blank=True)
cropped_photo = ImageRatioField('photo', '430x360')
#Using django-ajaximage
from ajaximage.fields import AjaxImageField
class Alumnus(models.Model):
photo = AjaxImageField(
upload_to='alumni_photos',
max_height=400,
max_width=400,
crop=True
)
While django-ajaximage uploads an image using AJAX, but it doesn't allow the admin to choose which part of the image he wants to be cropped, django-image-cropping crops an image in two steps: first we need to upload an image, save it to the db, then again we need to open the object and select crop portion, and save it again to the database, which i feel is unnecessarily cumbersome. Any suggestions?
It looks like you'll need a JS library in the browser that does the actual cropping. Then you can use AJAX to send it to the server.
DarkroomJS might be just what you need. It uses the HTML5 canvas to do the image editing in browser. It's actually got a few more features than you need, but it should get the job done.
The django-client-side-image-cropping library crops the image on client-side (Using the Croppie Javascript library) to a specific size. It is compatible with django-admin sites. It does not use AJAX. It uses InMemoryUploadedFile to temporarily store the original file.
django-cropper-image is an app I made for client side cropping and compressing uploaded images via Django’s app using with help cropper.js. github link django-cropper-image.
from django.db import models
from django_cropper_image.fields import ImageCropperField
class Images(models.Model):
image = ImageCropperField(upload_to='image',max_length=255)

Django Bulk Zip upload

I want to upload images to a gallery app. I want the user to be able to either load images normaly, or upload on zip file containing all the images for that gallery. Then it must be uncompressed and all images must be added to that model. This is for the admin site.
Any ideas?
You could either use the existing django-app django-photologue which enables you to do that or have a look at how it is implemented there: https://code.google.com/p/django-photologue/source/browse/trunk/photologue/models.py.
If you see that photlogue is lacking some of the functionality you need, you could also subclass and extend photologue's models in your app!