May be somebody faced with such issue and found good solution. I need rotate image in template before upload and save the record. I can rotate image view in template using JavaScript but it doesn't give any results, because image saves in original rotation. I saw several sites with such kind of feature and it's really useful.
You cannot get rotated image from Django templates. I assume you are working on a web app, where user uploads an image, rotates it and then saves it to later use. This can be done in the following way.
There is a lib for working with images in Python called PIL. You can use it in your view, which saves your image to the db. When a user plays with an image, use javascript for rotations on the front end. But when saving, let javascript send angles to the view and then make according changes to the uploaded image and then save to the db.
Links: How to use PIL for rotation in Python
Related
Hi everyone i'm working in a blog project in django framework where you can upload images and text. I have 30 images uploaded and the page takes 2234kb for most of its images when loading and all the images are loading at the same time. So when my users hit the page (the post list page) load all the images and its make the page slower. If anyhow i could load, not all the images, but a typically 20 images at a time when they are loading and rest images will be loading when the user scroll the page. is there anything how to do it i'm using html template in django. please help me.
What you are looking for is called image lazy loading. You can find here a guide about it. It should be fairly easy to implement, if you follow the instructions.
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!!!
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)
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
In a Django application, during registration, I want the user to be able to see the profile image he/she selects, rather than just see a path as done purely using django forms (for an example of what I want see pinterests registration form). I assume it should involve some ajax upload and it should be stored somewhere temporarily since the user might choose not to proceed with the registration even if the profile image has been uploaded, in which case the uploaded picture should be deleted.
I was wondering what is the best way of handeling this? Any examples out there you can point to?
Thanks!!!
You are correct that an AJAX upload will be needed.
Whether the upload is temporary or permanent, things will not change much in your implementation much. In both cases you will need to upload the image to a directory on your web server. In the temporary case, you may delete it after a short amount of time passes.
Here is a Django AJAX uploader: https://github.com/GoodCloud/django-ajax-uploader
Option 1
You can use the HTML5 FileAPI to show a thumbnail of a user-selected image before they upload it.
Option 2
You can upload the file using AJAX and then send back a thumbnail for them to preview