Frage

So i have a piece of code that looks like this:

<read-write buffer ptr 0x000000000286AB78, size 855 at 0x000000000286AB40>

I think it should be an image file :)

I look around and found some links to memoryview but looking at the documentation didn't seem like it would be what im after. Of course im rather new to programming.

I would like to save the file to a folder so that i could see the picture. =)

Anyone has idea how to solve this?

you can get access to it with this code, only replace [USERNAME] with your username:

import shutil
import os

shutil.copy('C:\Users\[USERNAME]\AppData\Local\Google\Chrome\User Data\Default\Favicons','C:\Users\[USERNAME]\Desktop')
con = sqlite3.connect('C:\Users\[USERNAME]\Desktop\Favicons')
cursor = con.cursor()
icon=''
for i in  cursor.execute("SELECT * FROM favicons WHERE id<6 limit 5;"): 
    icon= i,'favicons'
print('\n')
con.close()
os.remove('C:\Users\[USERNAME]\Desktop\Favicons')

--- ANSWER ----

import StringIO
from PIL import Image
file_ = StringIO.StringIO(icon)
image = Image.open(file_)
size=(128,128)
image=image.resize(size,Image.BILINEAR)
image.save('C:\icon.JPEG', 'JPEG')

Thanks for ideas :)

War es hilfreich?

Lösung

This is not an answer, but hopefully it is better than nothing. At least until something better comes around. I think you should take a look at Python Imaging Library (PIL). You should be able to use: Image.frombuffer(mode, size, data) here's some additional information. You can also try Image.open() as I suppose you are getting the image from a sql database?

import StringIO

data = read_from_database()

file = StringIO.StringIO(data)

image = Image.open(file)
image.thumbnail((128, 128))

outfile = StringIO.StringIO()
image.save(outfile, "JPEG")
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top