i need to do is modify the image in memory like resizing the image in memory etc ... with out saving it disk as i have to return back the image with out saving it disk
PIL supports the use of StringIO objects being passed in place of file
objects. StringIO objects are binary strings of variable length that are kept
in memory so i saved the image in stringio objects the following code does that for gif image
import Image
import StringIO
im = Image.open("/home/bharath/Desktop/photos/lena.gif")
fil=StringIO.St ringIO()
im.save(fil,"GI F")
cached_image=fi l.getvalue()
or for jpeg image
import Image
import StringIO
im = Image.open("/home/bharath/Desktop/photos/lena.jpg")
fil=StringIO.St ringIO()
im.save(fil,"JP EG")
cached_image=fi l.getvalue()
but i can't apply resize operation on cached_image as it a str object
but i found out that Image.formstrin g(mode, size, data, decoder, parameters) Creates an image memory from pixel data in a string so i did the following for gif image
ima=Image.froms tring('P',(128, 128),cached_ima ge,'gif')
imr=ima.resize( (64,64),Image.A NTIALIAS)
imr.save("/home/bharath/Desktop/photos/resize_lena3.gi f","GIF")
i am getting the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/bharath/Desktop/image.py", line 8, in <module>
ima=Image.froms tring('P',(128, 128),cached_ima ge,'gif')
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1744, in fromstring
im.fromstring(d ata, decoder_name, args)
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 577, in fromstring
raise ValueError("can not decode image data")
ValueError: cannot decode image data for jpeg image
ma=Image.fromst ring('P',(128,1 28),cached_imag e,'jpeg')
imr=ima.resize( (64,64),Image.A NTIALIAS)
imr.save("/home/bharath/Desktop/photos/resize_lena3.gi f","JPEG")
i am getting the following error ...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/bharath/Desktop/image.py", line 8, in <module>
ima=Image.froms tring('RGB',(12 8,128),cached_i mage,'jpeg')
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1744, in fromstring
im.fromstring(d ata, decoder_name, args)
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 570, in fromstring
d = _getdecoder(sel f.mode, decoder_name, args)
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 373, in _getdecoder
return apply(decoder, (mode,) + args + extra)
TypeError: function takes at least 3 arguments (1 given)
but if i remove the 4th parameter that is decoder_name i.e 'gif' or 'jpeg' in function Image.formstrin g(mode, size, data, decoder, parameters) there is no error(when decoder_name is not given it defaults to raw image type) .. image even gets resized and gets saved but that image is distorted image that shows that it is not decoded in correct way .. and when i want a image to be decoded according to a format i.e gif or jpeg i think i need to pass a extra parameter in the function Image.fromstrin g(mode, size, data, decoder, parameters) along with a decoder name to be decoded correctly .
pls can u tell what extra parameters i have to pass with an example (taking my example itself )
Reply
Forward
1 11090
I'm not sure what to pass in for the fromstring module. But you can do something like this to save a JPEG image from string buffer:
newImage = Image.fromstrin g('L', (325, 256), cached_image_st ring)
newImage.save(f ilename, "JPEG")
i need to do is modify the image in memory like resizing the image in memory etc ... with out saving it disk as i have to return back the image with out saving it disk
PIL supports the use of StringIO objects being passed in place of file
objects. StringIO objects are binary strings of variable length that are kept
in memory so i saved the image in stringio objects the following code does that for gif image
import Image
import StringIO
im = Image.open("/home/bharath/Desktop/photos/lena.gif")
fil=StringIO.St ringIO()
im.save(fil,"GI F")
cached_image=fi l.getvalue()
or for jpeg image
import Image
import StringIO
im = Image.open("/home/bharath/Desktop/photos/lena.jpg")
fil=StringIO.St ringIO()
im.save(fil,"JP EG")
cached_image=fi l.getvalue()
but i can't apply resize operation on cached_image as it a str object
but i found out that Image.formstrin g(mode, size, data, decoder, parameters) Creates an image memory from pixel data in a string so i did the following for gif image
ima=Image.froms tring('P',(128, 128),cached_ima ge,'gif')
imr=ima.resize( (64,64),Image.A NTIALIAS)
imr.save("/home/bharath/Desktop/photos/resize_lena3.gi f","GIF")
i am getting the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/bharath/Desktop/image.py", line 8, in <module>
ima=Image.froms tring('P',(128, 128),cached_ima ge,'gif')
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1744, in fromstring
im.fromstring(d ata, decoder_name, args)
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 577, in fromstring
raise ValueError("can not decode image data")
ValueError: cannot decode image data for jpeg image
ma=Image.fromst ring('P',(128,1 28),cached_imag e,'jpeg')
imr=ima.resize( (64,64),Image.A NTIALIAS)
imr.save("/home/bharath/Desktop/photos/resize_lena3.gi f","JPEG")
i am getting the following error ...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/bharath/Desktop/image.py", line 8, in <module>
ima=Image.froms tring('RGB',(12 8,128),cached_i mage,'jpeg')
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1744, in fromstring
im.fromstring(d ata, decoder_name, args)
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 570, in fromstring
d = _getdecoder(sel f.mode, decoder_name, args)
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 373, in _getdecoder
return apply(decoder, (mode,) + args + extra)
TypeError: function takes at least 3 arguments (1 given)
but if i remove the 4th parameter that is decoder_name i.e 'gif' or 'jpeg' in function Image.formstrin g(mode, size, data, decoder, parameters) there is no error(when decoder_name is not given it defaults to raw image type) .. image even gets resized and gets saved but that image is distorted image that shows that it is not decoded in correct way .. and when i want a image to be decoded according to a format i.e gif or jpeg i think i need to pass a extra parameter in the function Image.fromstrin g(mode, size, data, decoder, parameters) along with a decoder name to be decoded correctly .
pls can u tell what extra parameters i have to pass with an example (taking my example itself )
Reply
Forward
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bob |
last post by:
My understanding of the image string function is this, that it allows the
display of text in Graphics
As per the parameters it receives:
ImageString($image,6,$xpos,$ypos,$out,$col)
these params:
1. name of thew image to write on
2. size of the font
3. X co-ordinate of the first letter of the string
|
by: tlviewer |
last post by:
hello,
The script below is a prototype for loading playing card images
from the bitmap resource in cards.dll (WinXP)
I like the idea of not keeping copies of the images
as files.
I'm able to extract the card images as files, then load
them in pygame as a surface, but I keep getting errors
|
by: simon |
last post by:
Always when I need data reader in my programs, I simply have functions,
which creates it for me:
Dim rdr As SqlDataReader
dim sql as string
sql="myStoredProcedure"
rdr = createDataReader(sql, False)
And the functions are:
|
by: Steve Neill |
last post by:
Here's an interesting problem...
I have 2 functions, aFunc() and bFunc(). I call aFunc() passing a call
to bFunc() as a parameter. Function aFunc() executes bFunc(). Function
bFunc() lists the parameter values passed to it.
OK, here's the twist...
I want to add some parameters to bFunc() from inside aFunc(). Can that
be done?
|
by: Paul Allan |
last post by:
I am new to ASP.net (intermediate ASP developer). I am developing a ASP.net
web application and I am having some difficulty calling and passing
parameters to a function that is declared in my "codebehind" page.
Function declaration:
Sub MyFunction(ByVal sender As Object, ByVal e As System.EventArgs)
| |
by: Chris Ochs |
last post by:
I am trying to move all of the sql statements from my code into a pl/pgsql
function. I have one function for a transaction block that contains 10
inserts and I need to pass 50 parameters to it.
Well I can't do that, so I was playing around with passing the parameters in
as a varchar array, but then I have the issue of the variables being the
wrong type when I insert them.
I was playing around with trying to convert types, but it isn't...
|
by: astri |
last post by:
#include "Unit1.h"
#include "math.h"
#include "fixed_math.hpp"
#include "algorithm.h"
#define MBIT 0x4000
#define CBIT 16
long constbl;
void __fastcall TForm1::Button1Click(TObject *Sender)
|
by: Question123 |
last post by:
Hi
I am developing windows c# application in which i have given reference of third party DLL.
"Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang."
Does anybody knows why this error comes.??
plz help me..
|
by: Janwillem Borleffs |
last post by:
Tuxedo schreef:
You can check the Image.complete property; example:
img = new Image(100,100);
interval = setInterval('checkcomplete()', 100);
img.src = 'someimg';
function checkcomplete() {
if (window.complete) {
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |