Re: posting images from a mac
| From: | Mike Tuller | Date: | Fri, 18 Aug 2000 03:14:18 +0000 |
| Subject: | Re: posting images from a mac | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-12401@lists.php.net to get a copy of this message | ||
When you upload your files from the Mac, try transferring via binary format
rather than Macbinary or automatic.
----------
>From: "Jeroen Olthof" <webmaster@smurf.eu.org>
>To: php-general@lists.php.net
>Subject: [PHP] posting images from a mac
>Date: Thu, Aug 17, 2000, 8:12 PM
>
> hi,
>
> I'm having a problem getting some file info from a images posted in a form
> (type=file)
> images posted by a pc is working fine
>
> because I don't want to make a tmp file to get this info (like size , type
> jpg, gif or png ,height and width)
> I use a php script that I found here a while ago
> I'm personal think it has something to do with a max storing images data in
> hex instead of bin
>
> here is the script I'm using for getting the info from a posted file
>
> <?php
> /* Function: array elqGetImageFormat(string $dataFromImageFile)
>
> elqGetImageFormat is a php3 script with functionality similar to that
> of php3's internal function GetImageSize(string $fileName).
>
> The differences are as follows:
> - elqGetImageFormat takes the data from an image file as argument
> instead of the file name. Ie. you can use the function on
> data allready read from an image file, imagedata read from
> a blob field in a database, or similar.
>
> - elqGetImageFormat does NOT retrieve any JPEG/JFIF APP marker info,
> thus a call to
> elqGetImageData(string $dataFromImageFile, array [imageinfo])
> will generate an error.
>
> For further documentation on use of this function, consult your
> regular php3 reference on the GetImageSize function.
>
> Copyright notice:
> "This piece of code is copyright Oyvind Hallsteinsen, 2000.
> The code is to be seen as public domain, use it for whatever
> it's worth. The code is provided "as is", and comes with
> NO WARRANTY whatsoever.
> Please let this note follow your modified versions."
>
> Code originated from: http://www.elq.org
>
> - Oyvind Hallsteinsen aka Gosub / ELq - gosub@elq.org
>
> */
>
>
> /* Defining the JFIF markers we'll be using */
>
> define(M_SOF0, "\xc0"); /* Start Of Frame N */
> define(M_SOF1, "\xc1"); /* N indicates which
> compression process */
> define(M_SOF2, "\xc2"); /* Only SOF0-SOF2 are now in
> common use */
> define(M_SOF3, "\xc3");
> define(M_SOF5, "\xc5"); /* NB: codes C4 and CC are NOT
> SOF markers */
> define(M_SOF6, "\xc6");
> define(M_SOF7, "\xc7");
> define(M_SOF9, "\xc9");
> define(M_SOF10, "\xca");
> define(M_SOF11, "\xcb");
> define(M_SOF13, "\xcd");
> define(M_SOF14, "\xce");
> define(M_SOF15, "\xcf");
> define(M_EOI, "\xd9"); /* End Of Image (end of
> datastream) */
> define(M_SOS, "\xda"); /* Start Of Scan - image data start
> */
>
>
> function elqRead1Byte(&$imgData, &$imgPos) { /* Get 1 byte from data */
> $c = ord($imgData[$imgPos++]);
> return $c;
> }
>
>
> function elqRead2Bytes(&$imgData, &$imgPos) { /* Get 2 bytes from data */
> $c1 = (ord($imgData[$imgPos++])<<8);
> $c2 = ord($imgData[$imgPos++]);
> return ($c1 + $c2);
> }
>
>
> function elqNextMarker(&$imgData, &$imgPos) { /* Find next marker segment
> and return marker code */
> $c = elqRead1Byte($imgData, $imgPos);
> while ($c != 255) {
> $c = elqRead1Byte($imgData, $imgPos);
> }
> do {
> $c = elqRead1Byte($imgData, $imgPos);
> } while ($c == 255);
> return $c;
> }
>
>
> function elqProcessSof(&$imgData, &$imgPos) { /* Grab width/height from SOF
> segment */
> $imgPos += 3;
> $imgInfo[1] = elqRead2Bytes($imgData, $imgPos);
> $imgInfo[0] = elqRead2Bytes($imgData, $imgPos);
> return $imgInfo;
> }
>
>
> function elqSkipSegment(&$imgData, &$imgPos) { /* Skip entire marker
> segment (uninteresting) */
> $length = elqRead2Bytes($imgData, &$imgPos);
> $length -= 2;
> $imgPos += $length;
> }
>
>
> function elqJpegInfo(&$imgData) {
> $imgPos = 2;
> while($imgPos < strlen($imgData)) { /* Go through data and make sure
> loop exits even if jfif is corrupt */
> $marker = elqNextMarker($imgData, $imgPos);
> switch (chr($marker)) {
> case M_SOF0:
> case M_SOF1:
> case M_SOF2:
> case M_SOF3:
> case M_SOF5:
> case M_SOF6:
> case M_SOF7:
> case M_SOF9:
> case M_SOF10:
> case M_SOF11:
> case M_SOF12:
> case M_SOF13:
> case M_SOF14:
> case M_SOF15:
> $imgInfo = elqProcessSof($imgData, $imgPos);
> return $imgInfo;
> case M_EOI:
> case M_SOS:
> return FALSE; /* End loop in case we find one of these markers
> */
> default:
> elqSkipSegment($imgData, $imgPos); /* We're not interested in other
> markers */
> break;
> }
> }
> }
>
>
> function elqGenSizeArg($width, $height) { /* Generate Width/height args for
> img tag */
> return "width=\"" . $width . "\" height=\"" . $height .
> "\"";
> }
>
>
> function elqGetImageFormat(&$imgData) { /* Determine file type,
> extract/generate info */
> file://bin
> $gif_sig = "\x47\x49\x46";
> $jpeg_sig = "\xff\xd8\xff";
> $png_sig = "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a";
> file://hex
> $gif_sigh = bin2hex($gif_sig);
> $jpeg_sigh = bin2hex($jpeg_sig);
> $png_sigh = bin2hex($png_sig);
>
> if(strcmp($gif_sig, substr($imgData, 0, 3)) == 0) {
> $imgInfo[0] = ord($imgData[6]) + (ord($imgData[7])<<8);
> $imgInfo[1] = ord($imgData[8]) + (ord($imgData[9])<<8);
> $imgInfo[2] = "gif";
> } else if(strcmp($jpeg_sig, substr($imgData, 0, 3)) == 0) {
> $imgInfo = elqJpegInfo($imgData);
> if($imgInfo) $imgInfo[2] = "jpg";
> else $imgInfo = FALSE;
> } else if(strcmp($png_sig, substr($imgData, 0, 8)) == 0) {
> $imgInfo[0] = (ord($imgData[16])<<24) + (ord($imgData[17])<<16) +
> (ord($imgData[18])<<8) + ord($imgData[19]);
> $imgInfo[1] = (ord($imgData[20])<<24) + (ord($imgData[21])<<16) +
> (ord($imgData[22])<<8) + ord($imgData[23]);
> $imgInfo[2] = "png";
> } elseif(strcmp($gif_sigh, substr($imgData, 0, 3)) == 0) {
> $imgInfo[0] = ord($imgData[6]) + (ord($imgData[7])<<8);
> $imgInfo[1] = ord($imgData[8]) + (ord($imgData[9])<<8);
> $imgInfo[2] = "gif";
> } else if(strcmp($jpeg_sigh, substr($imgData, 0, 3)) == 0) {
> $imgInfo = elqJpegInfo($imgData);
> if($imgInfo) $imgInfo[2] = "jpg";
> else $imgInfo = FALSE;
> } else if(strcmp($png_sigh, substr($imgData, 0, 8)) == 0) {
> $imgInfo[0] = (ord($imgData[16])<<24) + (ord($imgData[17])<<16) +
> (ord($imgData[18])<<8) + ord($imgData[19]);
> $imgInfo[1] = (ord($imgData[20])<<24) + (ord($imgData[21])<<16) +
> (ord($imgData[22])<<8) + ord($imgData[23]);
> $imgInfo[2] = "png";
> } else $imgInfo = FALSE;
>
> if($imgInfo) { /* In case everything went well, generate
> width/height img argument */
> $imgInfo[3] = elqGenSizeArg($imgInfo[0], $imgInfo[1]);
> }
>
> return $imgInfo;
> }
>
> ?>
>
> can somebody help me with making it also work for a mac
>
> kind regards
> Jeroen Olthof
> Holland
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net