0

There is the function:

if form.is_valid():         
        image = grab_image(request.FILES['photo'])
        image_name = str(uuid.uuid4())
        path_to_image = settings.MEDIA_ROOT + '\\' + image_name + '.jpg'#Image path definition
        cropped_image = crop_face(image)    
        if cropped_image is not None:
            cv2.imwrite(path_to_image, cropped_image)#writing image to disk
            print(type(cropped_image))#'numpy.ndarray'
            uploaded_image = im.upload_image(path_to_image, title=image_name)#sending image to imgur
            os.remove(os.path.join(settings.MEDIA_ROOT, image_name + '.jpg'))#It is delete image from disk

I upload images to imgurl (using pyimgur) in this way: save the image to disk, to the media folder, and then call the im.upload_image (path_to_image) method, to which I transfer the path to the file and then delete the image from the disk. Is it possible to do without saving the image to disk? Image type - 'numpy.ndarray'

xomem
  • 147
  • 7
  • You could use temporary files which would remove the need to delete them manually afterwards. Have a look at the [tempfile](https://docs.python.org/3/library/tempfile.html) module. – mkrieger1 Mar 12 '19 at 08:14
  • Possible duplicate of [How to read image from in memory buffer (StringIO) or from url with opencv python library](https://stackoverflow.com/questions/13329445/how-to-read-image-from-in-memory-buffer-stringio-or-from-url-with-opencv-pytho) – Fabian Mar 12 '19 at 08:51
  • @Fabian I need to get a path to my image that is already in the buffer. – xomem Mar 12 '19 at 09:43
  • @xomem coudn't you upload the StringIO object ? Normally this should work since its an actual image. – Fabian Mar 12 '19 at 09:50
  • @Fabian like this `image_io = StringIO img=Image.fromarray(cropped_image, 'RGB') image_io.write(img) uploaded_image = im.upload_image(image_io, title=image_name)`? – xomem Mar 12 '19 at 11:46
  • @Fabian Apparently `im.upload_image` expects a file path, not a file-like object. – mkrieger1 Mar 12 '19 at 12:01

0 Answers0