Re: MIME file and gd
am 31.03.2008 22:35:33 von AmitOn Mar 28, 7:10=A0pm, petersprc
> Hi,
>
> The best way to get the image type is exif_imagetype. If you don't
> have that you can also use getimagesize.
>
> Now, if you want a general way to convert between image types, the
> easiest is to use the convert command that comes with ImageMagick.
> Here's a function to convert many image types:
>
>
>
> function imConvert($path, $newPath)
> {
> =A0 $cmd =3D 'convert ' . escapeshellarg($path) . ' ' .
> =A0 =A0 escapeshellarg($newPath) . ' 2>&1';
> =A0 exec($cmd, $output, $exitCode);
> =A0 if ($exitCode !=3D 0) {
> =A0 =A0 throw new Exception("Command \"$cmd\" failed with " .
> =A0 =A0 =A0 "exit code $exitCode: " . join("\n", $output));
> =A0 }
>
> }
>
> $path =3D dirname(__FILE__) . '/img.gif';
> $newPath =3D dirname(__FILE__) . '/im.jpg';
> imConvert($path, $newPath);
>
> ?>
>
> You can also use GD to do this. To convert from GIF to JPEG, you would
> call imagecreatefromgif then imagejpeg.
>
> Regards,
>
> John Peters
>
> On Mar 28, 9:08 pm,amit
>
>
>
> > On Mar 28, 5:58 pm,amit
>
> > > Hello group,
>
> > > I'm uploading some image files such as jpeg, png and gif. However, I
> > > must convert time to jpeg type. =A0I have few questions:
>
> > > 1) Can I convert time in using gd library?
>
> > > 2) Currently, I check the MIME file to see what is holding (thanks to
> > > Michael ) like image/jpg or image/gif or image/png. But what should be=
> > > the criteria? I'm checking:
>
> > > =A0 =A0 =A0 =A0 =A0 if ($img_array_info[mime] == "image/jpg" {
> > > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ...
> > > =A0 =A0 =A0 =A0 =A0 }
>
> > > However, there are some files that rather image/jpg they have image/
> > > jpeg as mime in their headers. Should I compare it agaisnt these two
> > > criteria or there are other things I have to consider too?
>
> > > Thanks,
> > >Amit
>
> > Currently I'm doing this:
>
> > if ( (strcasecmp($array_img_information[mime], "image/jpg") == 0 ) =
=A0||
> > (strcasecmp($array_img_information[mime], "image/jpeg") == 0 ) )
> > {
> > =A0 =A0echo "
OK, jpeg file
";}
>
> > else
> > {
> > =A0 =A0echo "
$array_img_information[mime]
";
> > =A0 =A0echo "
Not a jpeg file must conver it!
";
>
> > }
>
> > Is this a proper way or ....?
>
> > Thanks again.- Hide quoted text -
>
> - Show quoted text -
Thanks indeed for your help. Very nice function!
Regards,
Amit