I have a PHP script which calls on a software package to produce an image. The software has a function that allows the image to be displayed directly to the browser without first having to save the image. The examples that come with the software are all coded in ASP, and I can't find appropriate PHP counterparts that will do the same thing. Here is the ASP: Response.ContentType = "image/jpeg" Response.AddHeader "content-length", UBound(theData) - LBound(theData) + 1 Response.Addheader "content-disposition", "inline; filename=myimage.png" Response.BinaryWrite theData Code (markup): The way that I have coded it in PHP is: $theImage = $thePage->GetAs("image.jpg", 350, 270, 60); header('Content-type: image/jpeg'); imagejpeg($theImage) Code (markup): I have been needing to comment out the header function, because when I don't, the script seems to stop on that. When the header function is commented out, I get an error returned: Warning: imagejpeg(): supplied argument is not a valid Image resource in C:\wamp\www\david.php on line 12 Code (markup): Can anyone help me with this? I can save the image to disk just fine, but that won't work for the application that I am using it for, because it is on my home computer, and I don't want to fill my hard drive up with images....And the software package requires use of the COM component, so it will not work on a Linux machine, which is where my site is located. Thank you for any advice or help that you might offer.
Your ASP code uses COM component, so you have to rewrite the functionality which was provided by COM component as well in php. This could be quite complex.
I've already rewritten that part....I've gotten it to the point to where I can produce the image, and then save it to my hard disk....But that's where the problem lies...I need to access the image via the browser without having to save it first to the disk...I have it working now, but what I have to do is first save the image, then display it, and after it is displayed, delete it....That's too clunky for my taste, it would be much faster, and nicer, if I could skip the save and delete part, and simply just display it directly to the browser.
well... how are you getting the Image? Is someone uploading it? If so you can "push" the actual data to the screen as you are doing above (spoof the content-type). MAybe a good solution would to save the Image as BLOB in your DB, then display the BLOB image in screen (save/display in one step and no need to delete the file)
The reason that I am deleting it is because the software that I am using to produce the image is on my home computer, it requires use of a Windows machine. So I am calling the script from my Linux server to produce an image, and then saving it to my Linux server. The way that I have it set up now is it produces the image, saves it, then loads it into the browser, and then it is saved on my Linux server. It works fine, but it just seems as though there are a few too many steps, with the added save and delete. What I was hoping for was a PHP alternative to the "Responce.BinaryWrite" ASP function.
all asp stuff/code are built upon the foundation of the .net framework 1.x,2.x, including the com and dcom as m$ lead/direct it. task seem not easy,mate