You are here: Re: do I use fopen or fsockopen to get an image as a stream of bytes? « PHP Programming Language « IT news, forums, messages
Re: do I use fopen or fsockopen to get an image as a stream of bytes?

Posted by lkrubner on 11/04/05 20:05

Andy Hassall wrote:
> On 4 Nov 2005 09:42:55 -0800, lkrubner@geocities.com wrote:
>
> >How do I get an image like that, as a stream of bytes? Which function
> >do I use?
>
> Where are you getting it from?
> What format is the image in?
>
> You probably want a sequence of:
>
> http://uk.php.net/file_get_contents - get the image from a file or URL
>
> http://uk.php.net/imagecreatefromstring - create a GD image object

Well, I'm groping in the dark here, but I think that
imagecreatefromstring would give me an actual image, whereas what I
want is an actual string, and I don't know how to get a string from an
image file.

The thing with Postscript is that it is a plain text file. And to
represent an image in Postscript, I think that image needs to be
represented as a plain text listing of all its bytes.

I'm currently working at a manufacturing company that would like to
capture images (of a product) off of its website everytime it makes a
sale on the website, and then have that image and some text combined
into a Postscript file that prints out in the shipping department. The
image is suppose to help people see what product needs to be shipped.

I just wrote this code:


<?php

$image =
file_get_contents("http://www.mycompany.com/product_images/composite_standard_sm/318_1_SM_100.jpg");

$string = <<<EOF
%!
% Sample of printing text

/Times-Roman findfont % Get the basic font
20 scalefont % Scale the font to 20 points
setfont % Make it the current font

newpath % Start a new path
72 72 moveto % Lower left corner of text at (72, 72)
(14k White Gold 2 mm Classic Engagement Ring with Heart Shaped Side
Stones .80 ct. tw.) show % Typeset "Hello, world!"

100 200 translate
26 34 scale
26 34 8 [26 0 0 -34 0 34]
{<
$image
>}
image

showpage

EOF;

echo $string;
?>


Then I went to look at it in my browser. The image bytes show up as a
mess. It doesn't matter what character encoding I choose, it still
looks like a mess. IE asks me to download the file, which I do, and
then I open it in my text editor, and it still looks like a mess, with
strange Russian letters showing up.

The thing is, it doesn't look like plain text. Somehow I was expecting
a lot of 00089000. That kind of stuff. Not foreign letters.

So I'm left thinking that I'm not getting the raw bytes, or they are
getting interpreted somehow, along the way, whereas what I need is the
raw description of that image, because that is what Postscript needs.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация