def thumbnail(request, id_, hash_): raw_filepath = os.path.join(upload_directory, id_, request.GET.get("raw")) cache_dir = os.path.join(cache_root, id_) filepath = os.path.join(cache_dir, hash_ + ".jpeg") if not os.path.exists(filepath): try: generate_thumbnail(raw_filepath, cache_dir) except RawNotFound: raise django.http.Http404("{}/{}.jpeg".format(id_, hash_)) response = django.http.HttpResponse() response["X-Sendfile"] = filepath response["Content-Type"] = mimetypes.guess_type(filepath)[0] or "application/octet-stream" response["Content-Length"] = os.path.getsize(filepath) return response
def thumbnail(request, id_, hash_): raw_filepath = os.path.join(upload_directory, id_, request.GET.get("raw")) cache_dir = os.path.join(cache_root, id_) filepath = os.path.join(cache_dir, hash_ + ".jpeg") if not os.path.exists(filepath): try: generate_thumbnail(raw_filepath, cache_dir) except RawNotFound: raise django.http.Http404("{1}/{2}.jpeg".format(id_, hash_)) response = django.http.HttpResponse() response["X-Sendfile"] = filepath response["Content-Type"] = mimetypes.guess_type( filepath)[0] or "application/octet-stream" response["Content-Length"] = os.path.getsize(filepath) return response
def upload(request, obj_id=None): imagen = Imagenes() directorio = Directorios.objects.none() if obj_id: imagen = Imagenes.objects.get(id=obj_id, directorio__grupo__in=request.user.groups.all()) if imagen.deleted: contenido_no_disponible() directorio = imagen.directorio directorios_qs = Directorios.objects.not_deleted(padre=directorio.id, grupo__in=request.user.groups.all()) else: directorios_qs = Directorios.objects.not_deleted(padre=None, grupo__in=request.user.groups.all()) data = { 'forms':{ 'imagenes': ImagenesForm(instance=imagen, request=request), }, 'directorio': directorio, 'directorios': directorios_qs, 'imagenes': Imagenes.objects.none(), } if request.method == "POST": form = ImagenesForm(request.POST, request.FILES, instance=imagen, request=request) if form.is_valid(): imagen = form.instance imagen.save() if not utils.has_thumbnail(imagen.path): utils.generate_thumbnail(imagen.path) return HttpResponseRedirect("%s%s"%(reverse('imgbrowser_list'), '' if not imagen.directorio \ else imagen.directorio.fullpath) ) else: data['forms']['imagenes'] = form return render(request, "django_imgbrowser/upload.html", data)
def save_video(self, path, still): recd = self.createNewRecorded(constants.TYPE_VIDEO) os.rename(path, os.path.join(Instance.instancePath, recd.mediaFilename)) still = utils.generate_thumbnail(still) still.save(recd.make_thumb_path(), "png") self.createNewRecordedMd5Sums( recd ) gobject.idle_add(self.add_recd, recd, priority=gobject.PRIORITY_HIGH) gobject.idle_add(self.set_state, constants.STATE_READY)
def save_photo(self, pixbuf): recd = self.createNewRecorded(constants.TYPE_PHOTO) imgpath = os.path.join(Instance.instancePath, recd.mediaFilename) pixbuf.save(imgpath, "jpeg") pixbuf = utils.generate_thumbnail(pixbuf) pixbuf.save(recd.make_thumb_path(), "png") #now that we've saved both the image and its pixbuf, we get their md5s self.createNewRecordedMd5Sums( recd ) gobject.idle_add(self.add_recd, recd, priority=gobject.PRIORITY_HIGH) gobject.idle_add(self.activity.set_shutter_sensitive, True, priority=gobject.PRIORITY_HIGH)
def save_photo(self, pixbuf): recd = self.createNewRecorded(constants.TYPE_PHOTO) imgpath = os.path.join(Instance.instancePath, recd.mediaFilename) pixbuf.savev(imgpath, "jpeg", [], []) pixbuf = utils.generate_thumbnail(pixbuf) pixbuf.savev(recd.make_thumb_path(), "png", [], []) # now that we've saved both the image and its pixbuf, we get their md5s self.createNewRecordedMd5Sums(recd) GLib.idle_add(self.add_recd, recd, priority=GLib.PRIORITY_HIGH) GLib.idle_add(self.activity.set_shutter_sensitive, True, priority=GLib.PRIORITY_HIGH)
def save_video(self, path, still): recd = self.createNewRecorded(constants.TYPE_VIDEO) os.rename(path, os.path.join(Instance.instancePath, recd.mediaFilename)) image_path = os.path.join(Instance.instancePath, "videoPicture.png") image_path = utils.getUniqueFilepath(image_path, 0) still.savev(image_path, "png", [], []) recd.videoImageFilename = os.path.basename(image_path) still = utils.generate_thumbnail(still) still.savev(recd.make_thumb_path(), "png", [], []) self.createNewRecordedMd5Sums(recd) GLib.idle_add(self.add_recd, recd, priority=GLib.PRIORITY_HIGH) GLib.idle_add(self.set_state, constants.STATE_READY)
def save_video(self, path, still): recd = self.createNewRecorded(constants.TYPE_VIDEO) os.rename(path, os.path.join(Instance.instancePath, recd.mediaFilename)) image_path = os.path.join(Instance.instancePath, "videoPicture.png") image_path = utils.getUniqueFilepath(image_path, 0) still.savev(image_path, "png", [], []) recd.videoImageFilename = os.path.basename(image_path) still = utils.generate_thumbnail(still) still.savev(recd.make_thumb_path(), "png", [], []) self.createNewRecordedMd5Sums(recd) GLib.idle_add(self.add_recd, recd, priority=GLib.PRIORITY_HIGH) GLib.idle_add(self.set_state, constants.STATE_READY)
def save_audio(self, path, still): recd = self.createNewRecorded(constants.TYPE_AUDIO) os.rename(path, os.path.join(Instance.instancePath, recd.mediaFilename)) if still: image_path = os.path.join(Instance.instancePath, "audioPicture.png") image_path = utils.getUniqueFilepath(image_path, 0) still.save(image_path, "png") recd.audioImageFilename = os.path.basename(image_path) still = utils.generate_thumbnail(still) still.save(recd.make_thumb_path(), "png") self.createNewRecordedMd5Sums( recd ) gobject.idle_add(self.add_recd, recd, priority=gobject.PRIORITY_HIGH) gobject.idle_add(self.set_state, constants.STATE_READY)