Using r9679 (I can svn up if needbe ;) )
How exactly do I save my new resized image? I couldn't quite find any
documentation on this either.
The "easy" way almost seems to do it by writing out the file on my own
and just setting the imagefield to the filename... but there seems
like there should be a more integrated way.
Thanks,
-d
See Code:
@login_required
def add_image(request, slug, item_slug):
if request.method == 'POST':
form = NewMenuItemImageForm(request.POST, request.FILES)
if form.is_valid():
handle_uploaded_image(request.FILES['image'])
return HttpResponseRedirect('/')
else:
form = NewImageForm()
return render_to_response('add_image.html', locals(),
context_instance=RequestContext(request))
import Image, StringIO, md5
def handle_uploaded_image(i):
# resize image
imagefile = StringIO.StringIO(i.read())
imageImage = Image.open(imagefile)
(width, height) = imageImage.size
(width, height) = scale_dimensions(width, height,
longest_side=240)
imagefile = StringIO.StringIO()
imageImage.resize((width, height)).save(imagefile,'JPEG')
filename = md5.new(imagefile.getvalue()).hexdigest()+'.jpg'
# create MII
mii = MyItemImage()
# mii.image.save(imagefile.getvalue(), filename)
# mii.save()
# imagefile.close()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---