Read/Open image from instance of Python io.BufferedReader class












2















I'm struggling to properly open a TIFF image from an instance of Python's io.BufferedReader class. I download the image from a GCS path using the below lib, but I can't open seem to open the image with traditional tools.



# returns the <_io.BufferedReader>
file = beam.io.gcp.gcsio.GcsIO().open("<GCS_PATH>", 'r')

from PIL import Image
img = Image.open(file.read()) <---- Fails with "TypeError: embedded NUL character"

img = Image.open(file.raw) <--- Fails when any operations are performed with "IOError(err)"


I am open to other libraries besides PIL.



UPDATE



The following also fails:



img = Image.open(file)


It fails with an IOError, stating tempfile.tif: Cannot read TIFF header.










share|improve this question

























  • img = Image.open(bufferedreader)

    – Kinght 金
    Nov 21 '18 at 0:43











  • Ok. I think there may be an issue with the version of PIL I am using, because when I do that and then proceed with any operation such as img_array = np.array(img, dtype=np.uint8) or img.show() I get an error that starts with tempfile.tif: Cannot read TIFF header. and end with raise IOError(err) IOError: -2

    – Ryan Stack
    Nov 21 '18 at 1:12











  • IOError: -2: Make sure the file exists. os.path.exists(fpath)

    – Kinght 金
    Nov 21 '18 at 1:19













  • Well, I think the file is represented by the instance of io.BufferedReader class that I set to file variable. This example works with PNG images, so I think this is an issue with the multipage TIFF images

    – Ryan Stack
    Nov 21 '18 at 17:17











  • A BufferedReader is for sequential input, so if the TIFF code is trying to seek it's going to fail.

    – Mark Ransom
    Nov 21 '18 at 17:25
















2















I'm struggling to properly open a TIFF image from an instance of Python's io.BufferedReader class. I download the image from a GCS path using the below lib, but I can't open seem to open the image with traditional tools.



# returns the <_io.BufferedReader>
file = beam.io.gcp.gcsio.GcsIO().open("<GCS_PATH>", 'r')

from PIL import Image
img = Image.open(file.read()) <---- Fails with "TypeError: embedded NUL character"

img = Image.open(file.raw) <--- Fails when any operations are performed with "IOError(err)"


I am open to other libraries besides PIL.



UPDATE



The following also fails:



img = Image.open(file)


It fails with an IOError, stating tempfile.tif: Cannot read TIFF header.










share|improve this question

























  • img = Image.open(bufferedreader)

    – Kinght 金
    Nov 21 '18 at 0:43











  • Ok. I think there may be an issue with the version of PIL I am using, because when I do that and then proceed with any operation such as img_array = np.array(img, dtype=np.uint8) or img.show() I get an error that starts with tempfile.tif: Cannot read TIFF header. and end with raise IOError(err) IOError: -2

    – Ryan Stack
    Nov 21 '18 at 1:12











  • IOError: -2: Make sure the file exists. os.path.exists(fpath)

    – Kinght 金
    Nov 21 '18 at 1:19













  • Well, I think the file is represented by the instance of io.BufferedReader class that I set to file variable. This example works with PNG images, so I think this is an issue with the multipage TIFF images

    – Ryan Stack
    Nov 21 '18 at 17:17











  • A BufferedReader is for sequential input, so if the TIFF code is trying to seek it's going to fail.

    – Mark Ransom
    Nov 21 '18 at 17:25














2












2








2








I'm struggling to properly open a TIFF image from an instance of Python's io.BufferedReader class. I download the image from a GCS path using the below lib, but I can't open seem to open the image with traditional tools.



# returns the <_io.BufferedReader>
file = beam.io.gcp.gcsio.GcsIO().open("<GCS_PATH>", 'r')

from PIL import Image
img = Image.open(file.read()) <---- Fails with "TypeError: embedded NUL character"

img = Image.open(file.raw) <--- Fails when any operations are performed with "IOError(err)"


I am open to other libraries besides PIL.



UPDATE



The following also fails:



img = Image.open(file)


It fails with an IOError, stating tempfile.tif: Cannot read TIFF header.










share|improve this question
















I'm struggling to properly open a TIFF image from an instance of Python's io.BufferedReader class. I download the image from a GCS path using the below lib, but I can't open seem to open the image with traditional tools.



# returns the <_io.BufferedReader>
file = beam.io.gcp.gcsio.GcsIO().open("<GCS_PATH>", 'r')

from PIL import Image
img = Image.open(file.read()) <---- Fails with "TypeError: embedded NUL character"

img = Image.open(file.raw) <--- Fails when any operations are performed with "IOError(err)"


I am open to other libraries besides PIL.



UPDATE



The following also fails:



img = Image.open(file)


It fails with an IOError, stating tempfile.tif: Cannot read TIFF header.







python image opencv python-imaging-library google-cloud-dataflow






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 17:09







Ryan Stack

















asked Nov 20 '18 at 14:48









Ryan StackRyan Stack

313213




313213













  • img = Image.open(bufferedreader)

    – Kinght 金
    Nov 21 '18 at 0:43











  • Ok. I think there may be an issue with the version of PIL I am using, because when I do that and then proceed with any operation such as img_array = np.array(img, dtype=np.uint8) or img.show() I get an error that starts with tempfile.tif: Cannot read TIFF header. and end with raise IOError(err) IOError: -2

    – Ryan Stack
    Nov 21 '18 at 1:12











  • IOError: -2: Make sure the file exists. os.path.exists(fpath)

    – Kinght 金
    Nov 21 '18 at 1:19













  • Well, I think the file is represented by the instance of io.BufferedReader class that I set to file variable. This example works with PNG images, so I think this is an issue with the multipage TIFF images

    – Ryan Stack
    Nov 21 '18 at 17:17











  • A BufferedReader is for sequential input, so if the TIFF code is trying to seek it's going to fail.

    – Mark Ransom
    Nov 21 '18 at 17:25



















  • img = Image.open(bufferedreader)

    – Kinght 金
    Nov 21 '18 at 0:43











  • Ok. I think there may be an issue with the version of PIL I am using, because when I do that and then proceed with any operation such as img_array = np.array(img, dtype=np.uint8) or img.show() I get an error that starts with tempfile.tif: Cannot read TIFF header. and end with raise IOError(err) IOError: -2

    – Ryan Stack
    Nov 21 '18 at 1:12











  • IOError: -2: Make sure the file exists. os.path.exists(fpath)

    – Kinght 金
    Nov 21 '18 at 1:19













  • Well, I think the file is represented by the instance of io.BufferedReader class that I set to file variable. This example works with PNG images, so I think this is an issue with the multipage TIFF images

    – Ryan Stack
    Nov 21 '18 at 17:17











  • A BufferedReader is for sequential input, so if the TIFF code is trying to seek it's going to fail.

    – Mark Ransom
    Nov 21 '18 at 17:25

















img = Image.open(bufferedreader)

– Kinght 金
Nov 21 '18 at 0:43





img = Image.open(bufferedreader)

– Kinght 金
Nov 21 '18 at 0:43













Ok. I think there may be an issue with the version of PIL I am using, because when I do that and then proceed with any operation such as img_array = np.array(img, dtype=np.uint8) or img.show() I get an error that starts with tempfile.tif: Cannot read TIFF header. and end with raise IOError(err) IOError: -2

– Ryan Stack
Nov 21 '18 at 1:12





Ok. I think there may be an issue with the version of PIL I am using, because when I do that and then proceed with any operation such as img_array = np.array(img, dtype=np.uint8) or img.show() I get an error that starts with tempfile.tif: Cannot read TIFF header. and end with raise IOError(err) IOError: -2

– Ryan Stack
Nov 21 '18 at 1:12













IOError: -2: Make sure the file exists. os.path.exists(fpath)

– Kinght 金
Nov 21 '18 at 1:19







IOError: -2: Make sure the file exists. os.path.exists(fpath)

– Kinght 金
Nov 21 '18 at 1:19















Well, I think the file is represented by the instance of io.BufferedReader class that I set to file variable. This example works with PNG images, so I think this is an issue with the multipage TIFF images

– Ryan Stack
Nov 21 '18 at 17:17





Well, I think the file is represented by the instance of io.BufferedReader class that I set to file variable. This example works with PNG images, so I think this is an issue with the multipage TIFF images

– Ryan Stack
Nov 21 '18 at 17:17













A BufferedReader is for sequential input, so if the TIFF code is trying to seek it's going to fail.

– Mark Ransom
Nov 21 '18 at 17:25





A BufferedReader is for sequential input, so if the TIFF code is trying to seek it's going to fail.

– Mark Ransom
Nov 21 '18 at 17:25












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395564%2fread-open-image-from-instance-of-python-io-bufferedreader-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395564%2fread-open-image-from-instance-of-python-io-bufferedreader-class%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

WPF add header to Image with URL pettitions [duplicate]