Re: [pygame] image conversion in memory

2014-08-14 Thread diliup gabadamudalige
Thank you very much Carlos Zuniga and Noel Garwick for your suggestions. I
will look into both matters.


On Thu, Aug 14, 2014 at 11:03 PM, Noel Garwick 
wrote:

> Password protected zip would work.
>
> You can also look into what renpy's .rpa format does.
>
>
> On Thu, Aug 14, 2014 at 1:07 PM, diliup gabadamudalige 
> wrote:
>
>> I am reading up on creating and using zip files and may possibly use it,
>> What I am trying to do here is to hide the images on disk so that a user
>> of the program will not be able to manipulate or change the images. What
>> other way can you suggest?
>> Thanks for all the help so far.
>>
>>
>> On Wed, Aug 13, 2014 at 10:10 PM, Radomir Dopieralski <
>> pyg...@sheep.art.pl> wrote:
>>
>>> On 08/13/2014 04:35 PM, diliup gabadamudalige wrote:
>>> > This is the complete and correct code. Can anyone say what;s wrong?
>>> > Thanks in advance.
>>> >
>>> >
>>> > import pygame
>>> > import StringIO
>>> >
>>> > putimage = pygame.image.load("88keykbd.png")
>>> > buff = StringIO.StringIO()
>>> > buff.name  = '88keykbd.png'
>>> >
>>> > pygame.image.save(putimage, buff)
>>> >
>>> > putimage = buff.getvalue()
>>> > print "buff:", type(buff), "myimage:", type(putimage), "getimage:",
>>> > type(putimage)
>>> >
>>> > print len(putimage)
>>> > with open('myscrambledimage.dat', 'w') as newfile:
>>> > newfile.write(putimage)
>>> >
>>> > with open('myscrambledimage.dat', 'r') as newfile:
>>> > getimage= newfile.read()
>>> > print len(getimage)
>>>
>>> Open both files in binary mode, with 'wb' and 'rb' respectively.
>>> Especially if you are on some funny operating system, like Windows.
>>>
>>> Have you considered just putting all your images in a zip file, instead
>>> of encoding them in strange ways?
>>>
>>>
>>> --
>>> The Sheep
>>>
>>
>>
>>
>> --
>> Diliup Gabadamudalige
>>
>> http://www.diliupg.com
>> http://soft.diliupg.com/
>>
>>
>> **
>> This e-mail is confidential. It may also be legally privileged. If you
>> are not the intended recipient or have received it in error, please delete
>> it and all copies from your system and notify the sender immediately by
>> return e-mail. Any unauthorized reading, reproducing, printing or further
>> dissemination of this e-mail or its contents is strictly prohibited and may
>> be unlawful. Internet communications cannot be guaranteed to be timely,
>> secure, error or virus-free. The sender does not accept liability for any
>> errors or omissions.
>>
>> **
>>
>>
>


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] image conversion in memory

2014-08-14 Thread Noel Garwick
Password protected zip would work.

You can also look into what renpy's .rpa format does.


On Thu, Aug 14, 2014 at 1:07 PM, diliup gabadamudalige 
wrote:

> I am reading up on creating and using zip files and may possibly use it,
> What I am trying to do here is to hide the images on disk so that a user
> of the program will not be able to manipulate or change the images. What
> other way can you suggest?
> Thanks for all the help so far.
>
>
> On Wed, Aug 13, 2014 at 10:10 PM, Radomir Dopieralski  > wrote:
>
>> On 08/13/2014 04:35 PM, diliup gabadamudalige wrote:
>> > This is the complete and correct code. Can anyone say what;s wrong?
>> > Thanks in advance.
>> >
>> >
>> > import pygame
>> > import StringIO
>> >
>> > putimage = pygame.image.load("88keykbd.png")
>> > buff = StringIO.StringIO()
>> > buff.name  = '88keykbd.png'
>> >
>> > pygame.image.save(putimage, buff)
>> >
>> > putimage = buff.getvalue()
>> > print "buff:", type(buff), "myimage:", type(putimage), "getimage:",
>> > type(putimage)
>> >
>> > print len(putimage)
>> > with open('myscrambledimage.dat', 'w') as newfile:
>> > newfile.write(putimage)
>> >
>> > with open('myscrambledimage.dat', 'r') as newfile:
>> > getimage= newfile.read()
>> > print len(getimage)
>>
>> Open both files in binary mode, with 'wb' and 'rb' respectively.
>> Especially if you are on some funny operating system, like Windows.
>>
>> Have you considered just putting all your images in a zip file, instead
>> of encoding them in strange ways?
>>
>>
>> --
>> The Sheep
>>
>
>
>
> --
> Diliup Gabadamudalige
>
> http://www.diliupg.com
> http://soft.diliupg.com/
>
>
> **
> This e-mail is confidential. It may also be legally privileged. If you are
> not the intended recipient or have received it in error, please delete it
> and all copies from your system and notify the sender immediately by return
> e-mail. Any unauthorized reading, reproducing, printing or further
> dissemination of this e-mail or its contents is strictly prohibited and may
> be unlawful. Internet communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
>
> **
>
>


Re: [pygame] image conversion in memory

2014-08-14 Thread Carlos Zuniga
On Thu, Aug 14, 2014 at 12:07 PM, diliup gabadamudalige
 wrote:
> I am reading up on creating and using zip files and may possibly use it,
> What I am trying to do here is to hide the images on disk so that a user of
> the program will not be able to manipulate or change the images. What other
> way can you suggest?
> Thanks for all the help so far.
>

That's a pretty hard thing to do. If the user is supposed to be able
to open and see the images from the program, then they can still
PrintScreen and grab the image. All I can suggest there is adding a
watermark, so you at least know if they are grabbing it from the
screen.

If you zip the images with a password, then that password will still
be in the script, the user will be able to obtain it. You can try to
obfuscate the password but that only goes so far, anyone with some
python knowledge would be able to find it out.

Maybe compile the sensitive parts with cython and hope the users are
not curious?


Re: [pygame] image conversion in memory

2014-08-14 Thread diliup gabadamudalige
I am reading up on creating and using zip files and may possibly use it,
What I am trying to do here is to hide the images on disk so that a user of
the program will not be able to manipulate or change the images. What other
way can you suggest?
Thanks for all the help so far.


On Wed, Aug 13, 2014 at 10:10 PM, Radomir Dopieralski 
wrote:

> On 08/13/2014 04:35 PM, diliup gabadamudalige wrote:
> > This is the complete and correct code. Can anyone say what;s wrong?
> > Thanks in advance.
> >
> >
> > import pygame
> > import StringIO
> >
> > putimage = pygame.image.load("88keykbd.png")
> > buff = StringIO.StringIO()
> > buff.name  = '88keykbd.png'
> >
> > pygame.image.save(putimage, buff)
> >
> > putimage = buff.getvalue()
> > print "buff:", type(buff), "myimage:", type(putimage), "getimage:",
> > type(putimage)
> >
> > print len(putimage)
> > with open('myscrambledimage.dat', 'w') as newfile:
> > newfile.write(putimage)
> >
> > with open('myscrambledimage.dat', 'r') as newfile:
> > getimage= newfile.read()
> > print len(getimage)
>
> Open both files in binary mode, with 'wb' and 'rb' respectively.
> Especially if you are on some funny operating system, like Windows.
>
> Have you considered just putting all your images in a zip file, instead
> of encoding them in strange ways?
>
>
> --
> The Sheep
>



-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] image conversion in memory

2014-08-13 Thread Radomir Dopieralski
On 08/13/2014 04:35 PM, diliup gabadamudalige wrote:
> This is the complete and correct code. Can anyone say what;s wrong?
> Thanks in advance.
> 
> 
> import pygame
> import StringIO
> 
> putimage = pygame.image.load("88keykbd.png")
> buff = StringIO.StringIO()
> buff.name  = '88keykbd.png'
> 
> pygame.image.save(putimage, buff)
> 
> putimage = buff.getvalue()
> print "buff:", type(buff), "myimage:", type(putimage), "getimage:",
> type(putimage)
> 
> print len(putimage)
> with open('myscrambledimage.dat', 'w') as newfile:
> newfile.write(putimage)
> 
> with open('myscrambledimage.dat', 'r') as newfile:
> getimage= newfile.read()
> print len(getimage)

Open both files in binary mode, with 'wb' and 'rb' respectively.
Especially if you are on some funny operating system, like Windows.

Have you considered just putting all your images in a zip file, instead
of encoding them in strange ways?


-- 
The Sheep


Re: [pygame] image conversion in memory

2014-08-13 Thread diliup gabadamudalige
This is the complete and correct code. Can anyone say what;s wrong? Thanks
in advance.


import pygame
import StringIO

putimage = pygame.image.load("88keykbd.png")
buff = StringIO.StringIO()
buff.name = '88keykbd.png'

pygame.image.save(putimage, buff)

putimage = buff.getvalue()
print "buff:", type(buff), "myimage:", type(putimage), "getimage:",
type(putimage)

print len(putimage)
with open('myscrambledimage.dat', 'w') as newfile:
newfile.write(putimage)

with open('myscrambledimage.dat', 'r') as newfile:
getimage= newfile.read()
print len(getimage)




On Wed, Aug 13, 2014 at 7:46 PM, Noel Garwick 
wrote:

> since myimage is using pygame.image.load, it might be indexed?  On the
> other hand, it's also possible that pygame.image.save is actually
> performing some compression when it saves to a png format?  I'm not sure
> offhand, but something to check out.
>
>
> On Wed, Aug 13, 2014 at 10:02 AM, diliup gabadamudalige  > wrote:
>
>> Sorry there was a small error in the previous message. My apologies.
>>
>> import pygame
>> import StringIO
>>
>> myimage = pygame.image.load("88keykbd.png")
>> buff = StringIO.StringIO()
>> buff.name = '88keykbd.png'
>> pygame.image.save(myimage, buff)
>>
>> putimage = buff.getvalue()
>> print "buff:", type(buff), "myimage:", type(myimage), "getimage:",
>> type(putimage)
>>
>> print len(putimage)
>> with open('myscrambledimage.dat', 'w') as newfile:
>> newfile.write(putimage)
>>
>> with open('myscrambledimage.dat', 'r') as newfile:
>> getimage= newfile.read()
>> print len(getimage)
>>
>>
>>
>> On Wed, Aug 13, 2014 at 7:30 PM, diliup gabadamudalige > > wrote:
>>
>>> can any good soul out there tell me why these two files are not the same
>>> size?
>>>
>>> import pygame
>>> import StringIO
>>>
>>> myimage = pygame.image.load("88keykbd.png")
>>> buff = StringIO.StringIO()
>>> buff.name = '88keykbd.png'
>>> pygame.image.save(myimage, buff)
>>>
>>> putimage = buff.getvalue()
>>> print "buff:", type(buff), "myimage:", type(myimage), "getimage:",
>>> type(putimage)
>>>
>>> print len(getimage)
>>> with open('myscrambledimage.dat', 'w') as newfile:
>>> newfile.write(putimage)
>>>
>>> with open('myscrambledimage.dat', 'r') as newfile:
>>> getimage= newfile.read()
>>> print len(getimage)
>>>
>>> len(putimage) and len(getimage) are hugely different in size and I can't
>>> see why as it is putimage that is written to file and then read back as
>>> getimage.
>>>
>>> Clarification on this would be immensly welcome.
>>>
>>> Thank you in advance
>>>
>>>
>>> On Tue, Aug 12, 2014 at 9:53 PM, diliup gabadamudalige <
>>> dili...@gmail.com> wrote:
>>>
 Hi Radomir,

 Thanks for the response.
 ok. This is what i want to do
 i want to try to convert images into a string format and store them on
 disk. Better if they are unprintable characters.
 then when i want to see them i will run them thrugh a decryption python
 script and viola they will be displayed in pygame
 when i close the program again i will have only the encoded 'imageds'
 on the hd.
 I did this using

 get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH)
 with open(image_filename, "rb") as imageFile:
 imagestr = base64.b64encode(imageFile.read())
 ## create the text file name to save to disk
 text_filename = newpath + "s" + str(va.page) + ".dat"
 ## save imagestr(image as a textfle) to disk
 with open(text_filename, "wb") as f:
 f.write(imagestr)

 I wanted a better way and hence the question.

 stringio or cstringio is fine. i can save the string to disk but how
 can i convert it back to an image file?

 Thank you for your help.




 On Tue, Aug 12, 2014 at 11:12 AM, Radomir Dopieralski <
 pyg...@sheep.art.pl> wrote:

> On 08/11/2014 09:53 PM, diliup gabadamudalige wrote:
> > type(f) gives 
> > yourimage = f.getvalue()
> > with open('myscrambledimage.dat', 'w') as f:
> > f.write(yourimage)
> > so i coukld write this file to disk
> >
> > now how can i convert this back to an image?
> > Thanks in advance
>
> What are you actually tryig to do?
> I'm sure there is a simpler way.
>
> --
> The Sheep
>



 --
 Diliup Gabadamudalige

 http://www.diliupg.com
 http://soft.diliupg.com/


 **
 This e-mail is confidential. It may also be legally privileged. If you
 are not the intended recipient or have received it in error, please delete
 it and all copies from your system and notify the sender immediately by
 return e-mail. Any unauthorized reading, reproducing, printing or further
 dissemination of this e-mail or its contents is strictly prohibited and may
 be unlawful. Internet communications cannot be guaranteed to be timely,
 secure, error or viru

Re: [pygame] image conversion in memory

2014-08-13 Thread Noel Garwick
since myimage is using pygame.image.load, it might be indexed?  On the
other hand, it's also possible that pygame.image.save is actually
performing some compression when it saves to a png format?  I'm not sure
offhand, but something to check out.


On Wed, Aug 13, 2014 at 10:02 AM, diliup gabadamudalige 
wrote:

> Sorry there was a small error in the previous message. My apologies.
>
> import pygame
> import StringIO
>
> myimage = pygame.image.load("88keykbd.png")
> buff = StringIO.StringIO()
> buff.name = '88keykbd.png'
> pygame.image.save(myimage, buff)
>
> putimage = buff.getvalue()
> print "buff:", type(buff), "myimage:", type(myimage), "getimage:",
> type(putimage)
>
> print len(putimage)
> with open('myscrambledimage.dat', 'w') as newfile:
> newfile.write(putimage)
>
> with open('myscrambledimage.dat', 'r') as newfile:
> getimage= newfile.read()
> print len(getimage)
>
>
>
> On Wed, Aug 13, 2014 at 7:30 PM, diliup gabadamudalige 
> wrote:
>
>> can any good soul out there tell me why these two files are not the same
>> size?
>>
>> import pygame
>> import StringIO
>>
>> myimage = pygame.image.load("88keykbd.png")
>> buff = StringIO.StringIO()
>> buff.name = '88keykbd.png'
>> pygame.image.save(myimage, buff)
>>
>> putimage = buff.getvalue()
>> print "buff:", type(buff), "myimage:", type(myimage), "getimage:",
>> type(putimage)
>>
>> print len(getimage)
>> with open('myscrambledimage.dat', 'w') as newfile:
>> newfile.write(putimage)
>>
>> with open('myscrambledimage.dat', 'r') as newfile:
>> getimage= newfile.read()
>> print len(getimage)
>>
>> len(putimage) and len(getimage) are hugely different in size and I can't
>> see why as it is putimage that is written to file and then read back as
>> getimage.
>>
>> Clarification on this would be immensly welcome.
>>
>> Thank you in advance
>>
>>
>> On Tue, Aug 12, 2014 at 9:53 PM, diliup gabadamudalige > > wrote:
>>
>>> Hi Radomir,
>>>
>>> Thanks for the response.
>>> ok. This is what i want to do
>>> i want to try to convert images into a string format and store them on
>>> disk. Better if they are unprintable characters.
>>> then when i want to see them i will run them thrugh a decryption python
>>> script and viola they will be displayed in pygame
>>> when i close the program again i will have only the encoded 'imageds' on
>>> the hd.
>>> I did this using
>>>
>>> get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH)
>>> with open(image_filename, "rb") as imageFile:
>>> imagestr = base64.b64encode(imageFile.read())
>>> ## create the text file name to save to disk
>>> text_filename = newpath + "s" + str(va.page) + ".dat"
>>> ## save imagestr(image as a textfle) to disk
>>> with open(text_filename, "wb") as f:
>>> f.write(imagestr)
>>>
>>> I wanted a better way and hence the question.
>>>
>>> stringio or cstringio is fine. i can save the string to disk but how can
>>> i convert it back to an image file?
>>>
>>> Thank you for your help.
>>>
>>>
>>>
>>>
>>> On Tue, Aug 12, 2014 at 11:12 AM, Radomir Dopieralski <
>>> pyg...@sheep.art.pl> wrote:
>>>
 On 08/11/2014 09:53 PM, diliup gabadamudalige wrote:
 > type(f) gives 
 > yourimage = f.getvalue()
 > with open('myscrambledimage.dat', 'w') as f:
 > f.write(yourimage)
 > so i coukld write this file to disk
 >
 > now how can i convert this back to an image?
 > Thanks in advance

 What are you actually tryig to do?
 I'm sure there is a simpler way.

 --
 The Sheep

>>>
>>>
>>>
>>> --
>>> Diliup Gabadamudalige
>>>
>>> http://www.diliupg.com
>>> http://soft.diliupg.com/
>>>
>>>
>>> **
>>> This e-mail is confidential. It may also be legally privileged. If you
>>> are not the intended recipient or have received it in error, please delete
>>> it and all copies from your system and notify the sender immediately by
>>> return e-mail. Any unauthorized reading, reproducing, printing or further
>>> dissemination of this e-mail or its contents is strictly prohibited and may
>>> be unlawful. Internet communications cannot be guaranteed to be timely,
>>> secure, error or virus-free. The sender does not accept liability for any
>>> errors or omissions.
>>>
>>> **
>>>
>>>
>>
>>
>> --
>> Diliup Gabadamudalige
>>
>> http://www.diliupg.com
>> http://soft.diliupg.com/
>>
>>
>> **
>> This e-mail is confidential. It may also be legally privileged. If you
>> are not the intended recipient or have received it in error, please delete
>> it and all copies from your system and notify the sender immediately by
>> return e-mail. Any unauthorized reading, reproducing, printing or further
>> dissemination of this e-mail or its contents is strictly prohibited and may
>> be unlawful. Inte

Re: [pygame] image conversion in memory

2014-08-13 Thread diliup gabadamudalige
Sorry there was a small error in the previous message. My apologies.

import pygame
import StringIO

myimage = pygame.image.load("88keykbd.png")
buff = StringIO.StringIO()
buff.name = '88keykbd.png'
pygame.image.save(myimage, buff)

putimage = buff.getvalue()
print "buff:", type(buff), "myimage:", type(myimage), "getimage:",
type(putimage)

print len(putimage)
with open('myscrambledimage.dat', 'w') as newfile:
newfile.write(putimage)

with open('myscrambledimage.dat', 'r') as newfile:
getimage= newfile.read()
print len(getimage)



On Wed, Aug 13, 2014 at 7:30 PM, diliup gabadamudalige 
wrote:

> can any good soul out there tell me why these two files are not the same
> size?
>
> import pygame
> import StringIO
>
> myimage = pygame.image.load("88keykbd.png")
> buff = StringIO.StringIO()
> buff.name = '88keykbd.png'
> pygame.image.save(myimage, buff)
>
> putimage = buff.getvalue()
> print "buff:", type(buff), "myimage:", type(myimage), "getimage:",
> type(putimage)
>
> print len(getimage)
> with open('myscrambledimage.dat', 'w') as newfile:
> newfile.write(putimage)
>
> with open('myscrambledimage.dat', 'r') as newfile:
> getimage= newfile.read()
> print len(getimage)
>
> len(putimage) and len(getimage) are hugely different in size and I can't
> see why as it is putimage that is written to file and then read back as
> getimage.
>
> Clarification on this would be immensly welcome.
>
> Thank you in advance
>
>
> On Tue, Aug 12, 2014 at 9:53 PM, diliup gabadamudalige 
> wrote:
>
>> Hi Radomir,
>>
>> Thanks for the response.
>> ok. This is what i want to do
>> i want to try to convert images into a string format and store them on
>> disk. Better if they are unprintable characters.
>> then when i want to see them i will run them thrugh a decryption python
>> script and viola they will be displayed in pygame
>> when i close the program again i will have only the encoded 'imageds' on
>> the hd.
>> I did this using
>>
>> get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH)
>> with open(image_filename, "rb") as imageFile:
>> imagestr = base64.b64encode(imageFile.read())
>> ## create the text file name to save to disk
>> text_filename = newpath + "s" + str(va.page) + ".dat"
>> ## save imagestr(image as a textfle) to disk
>> with open(text_filename, "wb") as f:
>> f.write(imagestr)
>>
>> I wanted a better way and hence the question.
>>
>> stringio or cstringio is fine. i can save the string to disk but how can
>> i convert it back to an image file?
>>
>> Thank you for your help.
>>
>>
>>
>>
>> On Tue, Aug 12, 2014 at 11:12 AM, Radomir Dopieralski <
>> pyg...@sheep.art.pl> wrote:
>>
>>> On 08/11/2014 09:53 PM, diliup gabadamudalige wrote:
>>> > type(f) gives 
>>> > yourimage = f.getvalue()
>>> > with open('myscrambledimage.dat', 'w') as f:
>>> > f.write(yourimage)
>>> > so i coukld write this file to disk
>>> >
>>> > now how can i convert this back to an image?
>>> > Thanks in advance
>>>
>>> What are you actually tryig to do?
>>> I'm sure there is a simpler way.
>>>
>>> --
>>> The Sheep
>>>
>>
>>
>>
>> --
>> Diliup Gabadamudalige
>>
>> http://www.diliupg.com
>> http://soft.diliupg.com/
>>
>>
>> **
>> This e-mail is confidential. It may also be legally privileged. If you
>> are not the intended recipient or have received it in error, please delete
>> it and all copies from your system and notify the sender immediately by
>> return e-mail. Any unauthorized reading, reproducing, printing or further
>> dissemination of this e-mail or its contents is strictly prohibited and may
>> be unlawful. Internet communications cannot be guaranteed to be timely,
>> secure, error or virus-free. The sender does not accept liability for any
>> errors or omissions.
>>
>> **
>>
>>
>
>
> --
> Diliup Gabadamudalige
>
> http://www.diliupg.com
> http://soft.diliupg.com/
>
>
> **
> This e-mail is confidential. It may also be legally privileged. If you are
> not the intended recipient or have received it in error, please delete it
> and all copies from your system and notify the sender immediately by return
> e-mail. Any unauthorized reading, reproducing, printing or further
> dissemination of this e-mail or its contents is strictly prohibited and may
> be unlawful. Internet communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
>
> **
>
>


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally p

Re: [pygame] image conversion in memory

2014-08-13 Thread diliup gabadamudalige
can any good soul out there tell me why these two files are not the same
size?

import pygame
import StringIO

myimage = pygame.image.load("88keykbd.png")
buff = StringIO.StringIO()
buff.name = '88keykbd.png'
pygame.image.save(myimage, buff)

putimage = buff.getvalue()
print "buff:", type(buff), "myimage:", type(myimage), "getimage:",
type(putimage)

print len(getimage)
with open('myscrambledimage.dat', 'w') as newfile:
newfile.write(putimage)

with open('myscrambledimage.dat', 'r') as newfile:
getimage= newfile.read()
print len(getimage)

len(putimage) and len(getimage) are hugely different in size and I can't
see why as it is putimage that is written to file and then read back as
getimage.

Clarification on this would be immensly welcome.

Thank you in advance


On Tue, Aug 12, 2014 at 9:53 PM, diliup gabadamudalige 
wrote:

> Hi Radomir,
>
> Thanks for the response.
> ok. This is what i want to do
> i want to try to convert images into a string format and store them on
> disk. Better if they are unprintable characters.
> then when i want to see them i will run them thrugh a decryption python
> script and viola they will be displayed in pygame
> when i close the program again i will have only the encoded 'imageds' on
> the hd.
> I did this using
>
> get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH)
> with open(image_filename, "rb") as imageFile:
> imagestr = base64.b64encode(imageFile.read())
> ## create the text file name to save to disk
> text_filename = newpath + "s" + str(va.page) + ".dat"
> ## save imagestr(image as a textfle) to disk
> with open(text_filename, "wb") as f:
> f.write(imagestr)
>
> I wanted a better way and hence the question.
>
> stringio or cstringio is fine. i can save the string to disk but how can i
> convert it back to an image file?
>
> Thank you for your help.
>
>
>
>
> On Tue, Aug 12, 2014 at 11:12 AM, Radomir Dopieralski  > wrote:
>
>> On 08/11/2014 09:53 PM, diliup gabadamudalige wrote:
>> > type(f) gives 
>> > yourimage = f.getvalue()
>> > with open('myscrambledimage.dat', 'w') as f:
>> > f.write(yourimage)
>> > so i coukld write this file to disk
>> >
>> > now how can i convert this back to an image?
>> > Thanks in advance
>>
>> What are you actually tryig to do?
>> I'm sure there is a simpler way.
>>
>> --
>> The Sheep
>>
>
>
>
> --
> Diliup Gabadamudalige
>
> http://www.diliupg.com
> http://soft.diliupg.com/
>
>
> **
> This e-mail is confidential. It may also be legally privileged. If you are
> not the intended recipient or have received it in error, please delete it
> and all copies from your system and notify the sender immediately by return
> e-mail. Any unauthorized reading, reproducing, printing or further
> dissemination of this e-mail or its contents is strictly prohibited and may
> be unlawful. Internet communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
>
> **
>
>


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] image conversion in memory

2014-08-12 Thread diliup gabadamudalige
Hi Radomir,

Thanks for the response.
ok. This is what i want to do
i want to try to convert images into a string format and store them on
disk. Better if they are unprintable characters.
then when i want to see them i will run them thrugh a decryption python
script and viola they will be displayed in pygame
when i close the program again i will have only the encoded 'imageds' on
the hd.
I did this using

get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH)
with open(image_filename, "rb") as imageFile:
imagestr = base64.b64encode(imageFile.read())
## create the text file name to save to disk
text_filename = newpath + "s" + str(va.page) + ".dat"
## save imagestr(image as a textfle) to disk
with open(text_filename, "wb") as f:
f.write(imagestr)

I wanted a better way and hence the question.

stringio or cstringio is fine. i can save the string to disk but how can i
convert it back to an image file?

Thank you for your help.




On Tue, Aug 12, 2014 at 11:12 AM, Radomir Dopieralski 
wrote:

> On 08/11/2014 09:53 PM, diliup gabadamudalige wrote:
> > type(f) gives 
> > yourimage = f.getvalue()
> > with open('myscrambledimage.dat', 'w') as f:
> > f.write(yourimage)
> > so i coukld write this file to disk
> >
> > now how can i convert this back to an image?
> > Thanks in advance
>
> What are you actually tryig to do?
> I'm sure there is a simpler way.
>
> --
> The Sheep
>



-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] image conversion in memory

2014-08-11 Thread Radomir Dopieralski
On 08/11/2014 09:53 PM, diliup gabadamudalige wrote:
> type(f) gives 
> yourimage = f.getvalue()
> with open('myscrambledimage.dat', 'w') as f:
> f.write(yourimage)
> so i coukld write this file to disk
> 
> now how can i convert this back to an image?
> Thanks in advance

What are you actually tryig to do?
I'm sure there is a simpler way.

-- 
The Sheep


Re: [pygame] image conversion in memory

2014-08-11 Thread diliup gabadamudalige
type(f) gives 
yourimage = f.getvalue()
with open('myscrambledimage.dat', 'w') as f:
f.write(yourimage)
so i coukld write this file to disk

now how can i convert this back to an image?
Thanks in advance


On Tue, Aug 12, 2014 at 1:14 AM, diliup gabadamudalige 
wrote:

> so if i need to save that to memory i do with open('writetomyfile.dat',
> 'w') as f.
>
> Thank you very much for that explanation.
>
> the "image save" part confused me.
> How would you convert the file back to a jpg or png image?
> Please pardon me for asking all these questions.
>
> Thank you very much in advance
>
>
> On Tue, Aug 12, 2014 at 1:08 AM, Radomir Dopieralski 
> wrote:
>
>> On 08/11/2014 09:34 PM, diliup gabadamudalige wrote:
>> > Dear Radomir,
>> >
>> > s = pygame.image.load("88keykbd.png")
>> > f = StringIO.StringIO()
>> > f.name  = '88keykbd.jpg'
>> > pygame.image.save(s, f)
>> > pygame.image.load("88keykbd.jpg")
>> >
>> >
>> > yourimage = f.getvalue()
>> >
>> > why does the line pygame.image.load("88keykbd.jpg") throw an error? It
>> > throws pygame.error: Couldn't open 88keykbd.jpg
>> > I cant find the88keykbd.jpeg in the path
>>
>> Of course you can't -- no such file exists. It's only in memory, in the
>> f variable. That's the whole point. You can get to the *contents* of
>> that variable with f.getvalue().
>>
>> --
>> The Sheep
>>
>
>
>
> --
> Diliup Gabadamudalige
>
> http://www.diliupg.com
> http://soft.diliupg.com/
>
>
> **
> This e-mail is confidential. It may also be legally privileged. If you are
> not the intended recipient or have received it in error, please delete it
> and all copies from your system and notify the sender immediately by return
> e-mail. Any unauthorized reading, reproducing, printing or further
> dissemination of this e-mail or its contents is strictly prohibited and may
> be unlawful. Internet communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
>
> **
>
>


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] image conversion in memory

2014-08-11 Thread diliup gabadamudalige
so if i need to save that to memory i do with open('writetomyfile.dat',
'w') as f.

Thank you very much for that explanation.

the "image save" part confused me.
How would you convert the file back to a jpg or png image?
Please pardon me for asking all these questions.

Thank you very much in advance


On Tue, Aug 12, 2014 at 1:08 AM, Radomir Dopieralski 
wrote:

> On 08/11/2014 09:34 PM, diliup gabadamudalige wrote:
> > Dear Radomir,
> >
> > s = pygame.image.load("88keykbd.png")
> > f = StringIO.StringIO()
> > f.name  = '88keykbd.jpg'
> > pygame.image.save(s, f)
> > pygame.image.load("88keykbd.jpg")
> >
> >
> > yourimage = f.getvalue()
> >
> > why does the line pygame.image.load("88keykbd.jpg") throw an error? It
> > throws pygame.error: Couldn't open 88keykbd.jpg
> > I cant find the88keykbd.jpeg in the path
>
> Of course you can't -- no such file exists. It's only in memory, in the
> f variable. That's the whole point. You can get to the *contents* of
> that variable with f.getvalue().
>
> --
> The Sheep
>



-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] image conversion in memory

2014-08-11 Thread Radomir Dopieralski
On 08/11/2014 09:34 PM, diliup gabadamudalige wrote:
> Dear Radomir,
> 
> s = pygame.image.load("88keykbd.png")
> f = StringIO.StringIO()
> f.name  = '88keykbd.jpg'
> pygame.image.save(s, f)
> pygame.image.load("88keykbd.jpg")
> 
> 
> yourimage = f.getvalue()
> 
> why does the line pygame.image.load("88keykbd.jpg") throw an error? It
> throws pygame.error: Couldn't open 88keykbd.jpg
> I cant find the88keykbd.jpeg in the path

Of course you can't -- no such file exists. It's only in memory, in the
f variable. That's the whole point. You can get to the *contents* of
that variable with f.getvalue().

-- 
The Sheep


Re: Re: [pygame] image conversion in memory

2014-08-11 Thread diliup gabadamudalige
Dear Radomir,

s = pygame.image.load("88keykbd.png")
f = StringIO.StringIO()
f.name = '88keykbd.jpg'
pygame.image.save(s, f)
pygame.image.load("88keykbd.jpg")


yourimage = f.getvalue()

why does the line pygame.image.load("88keykbd.jpg") throw an error? It
throws pygame.error: Couldn't open 88keykbd.jpg
I cant find the88keykbd.jpeg in the path


On Mon, Aug 11, 2014 at 12:21 AM, Radomir Dopieralski 
wrote:

> On 08/08/2014 11:16 AM, diliup gabadamudalige wrote:
> > Hi all!
> >
> > Is there a way to convert a pygame surface to a png or jpeg IN MEMORY
> > instead of saving to disk and loading again?
> > something like
> > get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH) # grab the screen
> >
> > my_image = get_screen.convert(jpeg) # now convert the image to jpeg
> >
> > and now my_image is a jpeg image of get_screen
> >
> > I searched the net but couldn't find any other way other than save to
> > disk as jpeg and reload.
> >
> > Any positive OR negative help is very much appreciated.
>
> Sure, just use StringIO to use memory instead of a file.
>
> import pygame
> import StringIO
>
> s = pygame.image.load("yourimage.png")
> f = StringIO.StringIO()
> f.name = 'yourimage.jpg'
> pygame.image.save(s, f)
>
> yourimage = f.getvalue()
>
>
> --
> Radomir Dopieralski
>
>
>


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] image conversion in memory

2014-08-11 Thread diliup gabadamudalige
thanks I'll try it tonight



On Mon, Aug 11, 2014 at 4:00 PM, Radomir Dopieralski 
wrote:

> On 08/11/2014 11:40 AM, diliup gabadamudalige wrote:
> > get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH) # grab the screen
> >
> >  how can you concert get_screen to a jpeg or a png WITHOUT saving to
> > disk? In Pygame..
>
> I just told you. Use the example I gave you, it works.
>
>
> --
> The Sheep
>



-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] image conversion in memory

2014-08-11 Thread Radomir Dopieralski
On 08/11/2014 11:40 AM, diliup gabadamudalige wrote:
> get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH) # grab the screen
> 
>  how can you concert get_screen to a jpeg or a png WITHOUT saving to
> disk? In Pygame..

I just told you. Use the example I gave you, it works.


-- 
The Sheep


Re: Re: [pygame] image conversion in memory

2014-08-11 Thread diliup gabadamudalige
get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH) # grab the screen

 how can you concert get_screen to a jpeg or a png WITHOUT saving to disk?
In Pygame..

Thanks


On Mon, Aug 11, 2014 at 12:21 AM, Radomir Dopieralski 
wrote:

> On 08/08/2014 11:16 AM, diliup gabadamudalige wrote:
> > Hi all!
> >
> > Is there a way to convert a pygame surface to a png or jpeg IN MEMORY
> > instead of saving to disk and loading again?
> > something like
> > get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH) # grab the screen
> >
> > my_image = get_screen.convert(jpeg) # now convert the image to jpeg
> >
> > and now my_image is a jpeg image of get_screen
> >
> > I searched the net but couldn't find any other way other than save to
> > disk as jpeg and reload.
> >
> > Any positive OR negative help is very much appreciated.
>
> Sure, just use StringIO to use memory instead of a file.
>
> import pygame
> import StringIO
>
> s = pygame.image.load("yourimage.png")
> f = StringIO.StringIO()
> f.name = 'yourimage.jpg'
> pygame.image.save(s, f)
>
> yourimage = f.getvalue()
>
>
> --
> Radomir Dopieralski
>
>
>


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Fwd: Re: [pygame] image conversion in memory

2014-08-10 Thread Radomir Dopieralski
On 08/08/2014 11:16 AM, diliup gabadamudalige wrote:
> Hi all!
> 
> Is there a way to convert a pygame surface to a png or jpeg IN MEMORY
> instead of saving to disk and loading again?
> something like
> get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH) # grab the screen
> 
> my_image = get_screen.convert(jpeg) # now convert the image to jpeg
> 
> and now my_image is a jpeg image of get_screen
> 
> I searched the net but couldn't find any other way other than save to
> disk as jpeg and reload.
> 
> Any positive OR negative help is very much appreciated.

Sure, just use StringIO to use memory instead of a file.

import pygame
import StringIO

s = pygame.image.load("yourimage.png")
f = StringIO.StringIO()
f.name = 'yourimage.jpg'
pygame.image.save(s, f)

yourimage = f.getvalue()


-- 
Radomir Dopieralski




Re: [pygame] image conversion in memory

2014-08-10 Thread diliup gabadamudalige
Sorry I forgot to mention that I need to do this WITHOUT loading ajny more
modules or libraries.
Is it possible?


On Sun, Aug 10, 2014 at 7:01 PM, diliup gabadamudalige 
wrote:

> Hi Christopher!
>
> Thanks for the response. Below is my code
>
> pygame.image.save(get_screen, image_filename)  # save the file
> as jpeg
> ## reopen image and convert to text file
> with open(image_filename, "rb") as imageFile:
> imagestr = base64.b64encode(imageFile.read())
> ## create the text file name to save to disk
> text_filename = newpath + "s" + str(va.page) + ".dat"
> ## save imagestr(image as a textfle) to disk
> with open(text_filename, "wb") as f:
> f.write(imagestr)
>
> myscreen = pygame.image.load(image_filename).convert()
>
> I capture the screen image
> Is there any way that it can be converted directly to a text file like
> above without writing it to disk first?
> When you capture a screen it is a pygame surface. It is NOT a jpeg or a
> png. The only way to cojnvert it to a jpeg or png is to write it to disk
> and then reload it and then convert it to a text fle using base64.
>
> What I would like to do is to capture the screen, covert to jpeg and then
> convert to text file WITHOUT writing to disk first.
>
> Any ideas?
> Thanks for your support.
>
>
>
>
> On Fri, Aug 8, 2014 at 7:54 PM, Christopher Night 
> wrote:
>
>> It depends on what precisely you mean when you say that a python variable
>> is a jpeg image. Do you mean that it's a string containing the contents of
>> a jpeg image file? So if you wrote it to disk you'd get a jpeg image file?
>>
>> If that's what you mean, you can do it with PIL and StringIO. (There
>> might be an easier way.)
>>
>> import pygame
>> from PIL import Image
>> from cStringIO import StringIO
>>
>> # create an example pygame image
>> img = pygame.Surface((100, 100))
>> pygame.draw.circle(img, (255, 0, 0), (50, 50), 40)
>> # convert to PIL format
>> imgstr = pygame.image.tostring(img, "RGB", False)
>> pimg = Image.fromstring("RGB", img.get_size(), imgstr)
>> # save to string
>> s = StringIO()
>> pimg.save(s, "JPEG")
>> r = s.getvalue()
>> s.close()
>>
>> # r is a string with the contents of a jpeg file. to confirm:
>> open("img.jpg", "wb").write(r)
>>
>> However, this doesn't seem like a very useful thing to have (and if I
>> needed it so badly I would just write it to disk and read it back) so I may
>> be misunderstanding you.
>>
>>
>> On Fri, Aug 8, 2014 at 5:16 AM, diliup gabadamudalige 
>> wrote:
>>
>>> Hi all!
>>>
>>> Is there a way to convert a pygame surface to a png or jpeg IN MEMORY
>>> instead of saving to disk and loading again?
>>> something like
>>> get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH) # grab the screen
>>>
>>> my_image = get_screen.convert(jpeg) # now convert the image to jpeg
>>>
>>> and now my_image is a jpeg image of get_screen
>>>
>>> I searched the net but couldn't find any other way other than save to
>>> disk as jpeg and reload.
>>>
>>> Any positive OR negative help is very much appreciated.
>>>
>>> Thanks in advance
>>> Diliup Gabadamudalige
>>>
>>> http://www.diliupg.com
>>> http://soft.diliupg.com/
>>>
>>>
>>> **
>>> This e-mail is confidential. It may also be legally privileged. If you
>>> are not the intended recipient or have received it in error, please delete
>>> it and all copies from your system and notify the sender immediately by
>>> return e-mail. Any unauthorized reading, reproducing, printing or further
>>> dissemination of this e-mail or its contents is strictly prohibited and may
>>> be unlawful. Internet communications cannot be guaranteed to be timely,
>>> secure, error or virus-free. The sender does not accept liability for any
>>> errors or omissions.
>>>
>>> **
>>>
>>>
>>
>
>
> --
> Diliup Gabadamudalige
>
> http://www.diliupg.com
> http://soft.diliupg.com/
>
>
> **
> This e-mail is confidential. It may also be legally privileged. If you are
> not the intended recipient or have received it in error, please delete it
> and all copies from your system and notify the sender immediately by return
> e-mail. Any unauthorized reading, reproducing, printing or further
> dissemination of this e-mail or its contents is strictly prohibited and may
> be unlawful. Internet communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
>
> **
>
>


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**

Re: [pygame] image conversion in memory

2014-08-10 Thread diliup gabadamudalige
Hi Christopher!

Thanks for the response. Below is my code

pygame.image.save(get_screen, image_filename)  # save the file
as jpeg
## reopen image and convert to text file
with open(image_filename, "rb") as imageFile:
imagestr = base64.b64encode(imageFile.read())
## create the text file name to save to disk
text_filename = newpath + "s" + str(va.page) + ".dat"
## save imagestr(image as a textfle) to disk
with open(text_filename, "wb") as f:
f.write(imagestr)

myscreen = pygame.image.load(image_filename).convert()

I capture the screen image
Is there any way that it can be converted directly to a text file like
above without writing it to disk first?
When you capture a screen it is a pygame surface. It is NOT a jpeg or a
png. The only way to cojnvert it to a jpeg or png is to write it to disk
and then reload it and then convert it to a text fle using base64.

What I would like to do is to capture the screen, covert to jpeg and then
convert to text file WITHOUT writing to disk first.

Any ideas?
Thanks for your support.




On Fri, Aug 8, 2014 at 7:54 PM, Christopher Night 
wrote:

> It depends on what precisely you mean when you say that a python variable
> is a jpeg image. Do you mean that it's a string containing the contents of
> a jpeg image file? So if you wrote it to disk you'd get a jpeg image file?
>
> If that's what you mean, you can do it with PIL and StringIO. (There might
> be an easier way.)
>
> import pygame
> from PIL import Image
> from cStringIO import StringIO
>
> # create an example pygame image
> img = pygame.Surface((100, 100))
> pygame.draw.circle(img, (255, 0, 0), (50, 50), 40)
> # convert to PIL format
> imgstr = pygame.image.tostring(img, "RGB", False)
> pimg = Image.fromstring("RGB", img.get_size(), imgstr)
> # save to string
> s = StringIO()
> pimg.save(s, "JPEG")
> r = s.getvalue()
> s.close()
>
> # r is a string with the contents of a jpeg file. to confirm:
> open("img.jpg", "wb").write(r)
>
> However, this doesn't seem like a very useful thing to have (and if I
> needed it so badly I would just write it to disk and read it back) so I may
> be misunderstanding you.
>
>
> On Fri, Aug 8, 2014 at 5:16 AM, diliup gabadamudalige 
> wrote:
>
>> Hi all!
>>
>> Is there a way to convert a pygame surface to a png or jpeg IN MEMORY
>> instead of saving to disk and loading again?
>> something like
>> get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH) # grab the screen
>>
>> my_image = get_screen.convert(jpeg) # now convert the image to jpeg
>>
>> and now my_image is a jpeg image of get_screen
>>
>> I searched the net but couldn't find any other way other than save to
>> disk as jpeg and reload.
>>
>> Any positive OR negative help is very much appreciated.
>>
>> Thanks in advance
>> Diliup Gabadamudalige
>>
>> http://www.diliupg.com
>> http://soft.diliupg.com/
>>
>>
>> **
>> This e-mail is confidential. It may also be legally privileged. If you
>> are not the intended recipient or have received it in error, please delete
>> it and all copies from your system and notify the sender immediately by
>> return e-mail. Any unauthorized reading, reproducing, printing or further
>> dissemination of this e-mail or its contents is strictly prohibited and may
>> be unlawful. Internet communications cannot be guaranteed to be timely,
>> secure, error or virus-free. The sender does not accept liability for any
>> errors or omissions.
>>
>> **
>>
>>
>


-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**


Re: [pygame] image conversion in memory

2014-08-08 Thread Christopher Night
It depends on what precisely you mean when you say that a python variable
is a jpeg image. Do you mean that it's a string containing the contents of
a jpeg image file? So if you wrote it to disk you'd get a jpeg image file?

If that's what you mean, you can do it with PIL and StringIO. (There might
be an easier way.)

import pygame
from PIL import Image
from cStringIO import StringIO

# create an example pygame image
img = pygame.Surface((100, 100))
pygame.draw.circle(img, (255, 0, 0), (50, 50), 40)
# convert to PIL format
imgstr = pygame.image.tostring(img, "RGB", False)
pimg = Image.fromstring("RGB", img.get_size(), imgstr)
# save to string
s = StringIO()
pimg.save(s, "JPEG")
r = s.getvalue()
s.close()

# r is a string with the contents of a jpeg file. to confirm:
open("img.jpg", "wb").write(r)

However, this doesn't seem like a very useful thing to have (and if I
needed it so badly I would just write it to disk and read it back) so I may
be misunderstanding you.


On Fri, Aug 8, 2014 at 5:16 AM, diliup gabadamudalige 
wrote:

> Hi all!
>
> Is there a way to convert a pygame surface to a png or jpeg IN MEMORY
> instead of saving to disk and loading again?
> something like
> get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH) # grab the screen
>
> my_image = get_screen.convert(jpeg) # now convert the image to jpeg
>
> and now my_image is a jpeg image of get_screen
>
> I searched the net but couldn't find any other way other than save to disk
> as jpeg and reload.
>
> Any positive OR negative help is very much appreciated.
>
> Thanks in advance
> Diliup Gabadamudalige
>
> http://www.diliupg.com
> http://soft.diliupg.com/
>
>
> **
> This e-mail is confidential. It may also be legally privileged. If you are
> not the intended recipient or have received it in error, please delete it
> and all copies from your system and notify the sender immediately by return
> e-mail. Any unauthorized reading, reproducing, printing or further
> dissemination of this e-mail or its contents is strictly prohibited and may
> be unlawful. Internet communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability for any
> errors or omissions.
>
> **
>
>


[pygame] image conversion in memory

2014-08-08 Thread diliup gabadamudalige
Hi all!

Is there a way to convert a pygame surface to a png or jpeg IN MEMORY
instead of saving to disk and loading again?
something like
get_screen = SCREEN.subsurface(0, 0, SCREENW, SCREENH) # grab the screen

my_image = get_screen.convert(jpeg) # now convert the image to jpeg

and now my_image is a jpeg image of get_screen

I searched the net but couldn't find any other way other than save to disk
as jpeg and reload.

Any positive OR negative help is very much appreciated.

Thanks in advance
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**