473,651 Members | 3,011 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

print imagedata from string variable

Hi folks,

I got a windows com executable which returns a jpg image in a BSTR.

Let's say, the var that holds the data is $imgData.

With perl, in a cgi script, I may simpy write:
8<--------8<--------8<--------8<--------8<--------
$| = 1;
print "Content-type: image/jpeg\n\n";
binmode(STDOUT) ;
print $imgData;
8<--------8<--------8<--------8<--------8<--------
and the Image is propperly printed to the Client-Browser.

Now I want to achieve the same with php, but I just can't find a way to
treat the data as binary instead of a formated string.
As far as I know, echo $imgData shouldn't expect a formated string, as print
does.

(I know, returning a Safearray from the com executable would be a better way
and probably I will also do it that way, but at the moment, I'm trying to
solve this problem.)

It'll make me very happy if someone could give me a hint...

Many thanks in advance,
yours Henri
Jul 17 '05 #1
7 2609
"Henri Schomäcker" <hs@byteconcept s.de> wrote in message
news:cd******** *****@news.t-online.com...
Hi folks,

I got a windows com executable which returns a jpg image in a BSTR.

Let's say, the var that holds the data is $imgData.

With perl, in a cgi script, I may simpy write:
8<--------8<--------8<--------8<--------8<--------
$| = 1;
print "Content-type: image/jpeg\n\n";
binmode(STDOUT) ;
print $imgData;
8<--------8<--------8<--------8<--------8<--------
and the Image is propperly printed to the Client-Browser.

Now I want to achieve the same with php, but I just can't find a way to
treat the data as binary instead of a formated string.
As far as I know, echo $imgData shouldn't expect a formated string, as print does.

(I know, returning a Safearray from the com executable would be a better way and probably I will also do it that way, but at the moment, I'm trying to
solve this problem.)


www.php.net/imagecreatefromstring
www.php.net/imagejpeg

though I haven't done it from a string before.

- Virgil
Jul 17 '05 #2
On Fri, 16 Jul 2004 19:18:42 +0200, Henri Schomäcker <hs@byteconcept s.de>
wrote:
I got a windows com executable which returns a jpg image in a BSTR.

Let's say, the var that holds the data is $imgData.

With perl, in a cgi script, I may simpy write:
8<--------8<--------8<--------8<--------8<--------
$| = 1;
print "Content-type: image/jpeg\n\n";
binmode(STDOUT );
print $imgData;
8<--------8<--------8<--------8<--------8<--------
and the Image is propperly printed to the Client-Browser.

Now I want to achieve the same with php, but I just can't find a way to
treat the data as binary instead of a formated string.
As far as I know, echo $imgData shouldn't expect a formated string, as print
does.


I don't know what you mean by a "formated string" with regards to print.
You can print binary data without any special treatment.

(If you've opened a filehandle and are outputting to that, you have to open it
with 'b' in the open mode, but output to the browser is binary-safe by
default).

So it becomes just:

<?php
// magic to get $imgData = a jpeg
header('Content-type: image/jpeg');
print $imgData;
?>

--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #3
> Andy Hassall wrote:
I don't know what you mean by a "formated string" with regards to print.
You can print binary data without any special treatment.

(If you've opened a filehandle and are outputting to that, you have to
open it
with 'b' in the open mode, but output to the browser is binary-safe by
default).

So it becomes just:

<?php
// magic to get $imgData = a jpeg
header('Content-type: image/jpeg');
print $imgData;
?>

--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space


;-) Yes, this is exactly what I mean, but it does NOT work.
It should be typeless, but it seems it isn't because it just recognices the
data until the first 0 like a 0 terminated string and that wouldn't be
typeless.

As I wrote, It works with perl, which really handles the data typeless, but
when I recieve the Imagedata with php, php handles the received data like
vbscript as a BSTR type, which really is send by the com object.

Here's how I get the data with php, perhapst I should do this another way?
8<--------8<--------8<--------8<--------8<--------8<--------8<--------
$comObj = new COM("mytools.My Method") or Die ("Failed to connect to Com");
$imgData['img'] = $comObj->getImage() or Die ("Couldn't get data from
Object");
8<--------8<--------8<--------8<--------8<--------8<--------8<--------

Many thanks for the replys,
yours Henri
Jul 17 '05 #4
Oops, sorry I have to make a correction,

By mistake, I copied another try but the correct code I used is:
8<--------8<--------8<--------8<--------8<--------8<--------8<--------
$imgData = $comObj->getImage() or Die ("Couldn't get data from Object");
8<--------8<--------8<--------8<--------8<--------8<--------8<--------

Many thanks for the replys,
yours Henri

Jul 17 '05 #5
On Sat, 17 Jul 2004 13:32:15 +0200, Henri Schomäcker <hs@byteconcept s.de>
wrote:
Andy Hassall wrote:
I don't know what you mean by a "formated string" with regards to print.
You can print binary data without any special treatment.

(If you've opened a filehandle and are outputting to that, you have to
open it
with 'b' in the open mode, but output to the browser is binary-safe by
default).

So it becomes just:

<?php
// magic to get $imgData = a jpeg
header('Content-type: image/jpeg');
print $imgData;
?>


;-) Yes, this is exactly what I mean, but it does NOT work.
It should be typeless, but it seems it isn't because it just recognices the
data until the first 0 like a 0 terminated string and that wouldn't be
typeless.

As I wrote, It works with perl, which really handles the data typeless, but
when I recieve the Imagedata with php, php handles the received data like
vbscript as a BSTR type, which really is send by the com object.

Here's how I get the data with php, perhapst I should do this another way?
8<--------8<--------8<--------8<--------8<--------8<--------8<--------
$comObj = new COM("mytools.My Method") or Die ("Failed to connect to Com");
$imgData['img'] = $comObj->getImage() or Die ("Couldn't get data from
Object");
8<--------8<--------8<--------8<--------8<--------8<--------8<--------


It's sounding like it's not a core PHP problem (since PHP strings and print
can definitely handle binary data containing NUL bytes), but rather a problem
somewhere in the COM extension that's stopping the full data reaching the PHP
variable. I've not used the COM extension myself so can't suggest much more on
that. Perhaps try http://bugs.php.net ?

--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #6
> Virgil Green wrote:

www.php.net/imagecreatefromstring
www.php.net/imagejpeg

though I haven't done it from a string before.

- Virgil


Thanks, but these functions are non-standart extensions that are part of the
gd extension in php, which I don't want to use because the imagedata is
already returned correctly by the com object.

But anyway, thanks for the reply,
yours Henri
Jul 17 '05 #7
>> On Sat, 17 Jul 2004 13:32:15 +0200, Henri Schomäcker wrote:

As I wrote, It works with perl, which really handles the data typeless,
but when I recieve the Imagedata with php, php handles the received data
like vbscript as a BSTR type, which really is send by the com object.

Here's how I get the data with php, perhapst I should do this another way?
8<--------8<--------8<--------8<--------8<--------8<--------8<--------
$comObj = new COM("mytools.My Method") or Die ("Failed to connect to Com");
$imgData = $comObj->getImage() or Die ("Couldn't get data from Object");
8<--------8<--------8<--------8<--------8<--------8<--------8<--------
Andy Hassall wrote:

It's sounding like it's not a core PHP problem (since PHP strings and
print
can definitely handle binary data containing NUL bytes), but rather a
problem somewhere in the COM extension that's stopping the full data
reaching the PHP variable. I've not used the COM extension myself so can't
suggest much more on that. Perhaps try http://bugs.php.net ?

--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space


Seems you're right. I also tried to set a Variant type of $imgData to VT_UI1
before, but it had no effect.

I also searched http://bugs.php.net but couldn't find a bug related to my
problem. It also seems that not many developers really use com with php
which makes searching for a solution really hard.

I think I'll give up and use the time to recode the com component to return
a Safearray so using it with other languages than perl will be made easier.

Many thanks for all your answers,
yours Henri
Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
5570
by: Henri Schomaecker | last post by:
Hi folks, I'm still having the problem that I don't know how I can print the data of a jpeg image. I got the imagedata as return-value from a COM object. The imagedata are hold in a Variant SafeArray of bytes. Now I want to print the image header: 8<--------8<--------8<--------8<--------8<-------- header("Content-Type: image/jpeg") 8<--------8<--------8<--------8<--------8<--------
12
2260
by: opt_inf_env | last post by:
Hello, Should be a simple question... Do you know why the following two lines print not "123" but only "1"? $aaa = 123; print $aaa;
2
2000
by: Balaji | last post by:
Hello Eveybody, I have written a method which prints the prefix notation of any expression. here is the method... def PrintPrefix(expr): if expr.__class__==E: print expr.operator, PrintPrefix(expr.left),
6
2357
by: Ruchika | last post by:
Hi, I am new to Python, so this may be a very simple question for most of you. What does the % operator stand for in Python? I came across a script that uses the % operator as follows - def sync(delf,name): os.popen3( 'P4 -s sync -f %s' % name) I would suspect that this just replaces the %s with the value of name.
23
63663
by: stewart.midwinter | last post by:
No doubt I've overlooked something obvious, but here goes: Let's say I assign a value to a var, e.g.: myPlace = 'right here' myTime = 'right now' Now let's say I want to print out the two vars, along with their names. I could easily do this: print "myPlace = %s, myTime = %s" % (myPlace, myTime)
10
17961
by: sam | last post by:
Hi, Can anyone tell me how to print a file name from ifstream? the following cout code does not print the filename I created with ifstream preivous: ifstream is; is.open ("text.txt");
3
2662
by: DD | last post by:
I have a mainform with a subform. > The main form has a dropdown box "chooseMonth", in the afterupdate event > i requery the subform so all records with the same date are viewed. > Now i only want to print the selected records of the selected month > Can any one advise on the below Below is code i am trying to adapt (Thanks Don) 1.This first part is causing me problems so i have deleted it as it strikes me that it is looking for a...
1
5701
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out of a Microsoft book, "Visual Basic,Net Step by Step" in Chapter 18. All but the bottom two subroutines will open a text file, and then allow me to use the above controls, example 1. The bottom two subroutines will print a graphic file, example...
0
8361
marktang
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...
0
8278
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,...
0
8807
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8701
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8584
tracyyun
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...
0
5615
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();...
0
4144
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...
1
2701
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
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.