Article View: alt.comp.lang.php
Article #13Re: Issues with ImageGIF and ImageJPEG functions
From: NoT GorillA
Date: Mon, 07 Oct 2002 17:33
Date: Mon, 07 Oct 2002 17:33
94 lines
4553 bytes
4553 bytes
"TheXhippy" <thexhippy@notmail.com> wrote in message
news:ansblo$88m$1@paris.btinternet.com...
> Hello,
>
> I'm building a system where a user can upload an image to my server via an
> html form like this:
>
> <FORM NAME="add_img" METHOD="post" ACTION="showpic.php"
> ENCTYPE="multipart/form-data">
> <INPUT TYPE="file" NAME="image">
> <INPUT TYPE="submit" NAME="Submit" VALUE="Add New Property">
> </FORM>
>
> the file it posts to looks like this:
>
> <?php
> $store_dir= "../photo/";
>
> if(strlen($HTTP_POST_FILES['image']['name'])>0)
> {
> $tmp_array = explode(".", $HTTP_POST_FILES['image']['name']);
> $tmp_length = count($tmp_array);
> $extn = strtolower($tmp_array[$tmp_length-1]);
> $store_name = 'resized.'.$extn;
> @copy($HTTP_POST_FILES['image']['tmp_name'],$store_dir.$store_name);
> @unlink($HTTP_POST_FILES['image']['tmp_name']);
> $size=GetImageSize($store_dir.$store_name);
> $max_width = 300;
> $max_height = 200;
> $width_ratio = ($size[0] / $max_width);
> $height_ratio = ($size[1] / $max_height);
> $width_ratio>=$height_ratio ? $ratio = $width_ratio : $ratio =
> $height_ratio;
> $new_width = ($size[0] / $ratio);
> $new_height = ($size[1] / $ratio);
> $resized_image = imagecreate($new_width,$new_height);
> switch($extn)
> {
> case 'gif':
> $src_img = imagecreatefromgif($store_dir.$store_name);
> imagecopyresampled($resized_image, $src_img, 0,0,0,0,
> $new_width,$new_height,$size[0],$size[1]);
> imagegif($resized_image,$store_dir.$store_name);
> break;
>
> case 'jpg':
> $src_img = imagecreatefromjpeg($store_dir.$store_name);
> imagecopyresampled($resized_image, $src_img, 0,0,0,0,
> $new_width,$new_height,$size[0],$size[1]);
> imagejpeg($resized_image,$store_dir.$store_name);
> break;
> }
> }
> print('<IMG SRC="'.$store_dir.$store_name.'"><BR>');
> ?>
>
>
> This takes the uploaded image and resizes it to fit within a maximum
> bounding box of 300x200 pixels but keeps the originals aspect ratio and it
> all works fine except that:
>
> 1) It trashes the colours on jpegs so they look like 16 colour posterised
> crap
>
> and
>
> 2) It creates gifs that my browser just won't show on screen - the file is
> there I can ftp it down and view it in Photoshop but it shows broken image
> on the screen.
>
> So what am I doing wrong? I assume there is a default colour depth of an
> image created using imagecreate() and it seems to be the standard first 16
> and I assume therefore I need to change this before I go
> imagecopyresampled() or imagejpeg() but I cannot find any info on this.
>
> Using
> GD > 2
> PHP 4.06
> linux kernel 2.4.18
> apache 1.3.23
>
> Thanks in advance
>
> TheXhippy
>
>
>
don't you need an imagecreatetruecolor() in there?
--
NoT
I'd rather not take sides until I hear the monkey's version.
Technical Details
Message-ID:
<%yjo9.14361$975.722689@newsfep2-win.server.ntli.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!freenix!proxad.net!proxad.net!newspeer1-gui.server.ntli.net!ntli.net!newsfep2-win.server.ntli.net.POSTED!53ab2750!not-for-mailReferences:
<ansblo$88m$1@paris.btinternet.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 102e3b,b8cc33b4c63e8aa8 X-Google-Attributes: gid102e3b,public X-Google-Thread: 10701e,b8cc33b4c63e8aa8 X-Google-Attributes: gid10701e,public X-Google-Thread: 1107bb,b8cc33b4c63e8aa8 X-Google-Attributes: gid1107bb,public X-Google-Thread: 10ce1c,b8cc33b4c63e8aa8 X-Google-Attributes: gid10ce1c,public X-Google-Thread: f9981,b8cc33b4c63e8aa8 X-Google-Attributes: gidf9981,public X-Google-ArrivalTime: 2002-10-07 10:32:46 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!freenix!proxad.net!proxad.net!newspeer1-gui.server.ntli.net!ntli.net!newsfep2-win.server.ntli.net.POSTED!53ab2750!not-for-mail From: "NoT GorillA" <bobremovetheobviouswilson26@hotmail.com> Newsgroups: alt.comp.lang.php,alt.html.server-side,alt.php,ba.php,comp.lang.php References: <ansblo$88m$1@paris.btinternet.com> Subject: Re: Issues with ImageGIF and ImageJPEG functions Lines: 96 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Message-ID: <%yjo9.14361$975.722689@newsfep2-win.server.ntli.net> Date: Mon, 7 Oct 2002 18:33:09 +0100 NNTP-Posting-Host: 80.6.203.228 X-Complaints-To: abuse@ntlworld.com X-Trace: newsfep2-win.server.ntli.net 1034011963 80.6.203.228 (Mon, 07 Oct 2002 18:32:43 BST) NNTP-Posting-Date: Mon, 07 Oct 2002 18:32:43 BST Organization: ntl Cablemodem News Service