473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

MIME file and gd


Hello group,

I'm uploading some image files such as jpeg, png and gif. However, I
must convert time to jpeg type. I 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:

if ($img_array_info[mime] == "image/jpg" {
...
}

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

Mar 29 '08 #1
3 1641
On Mar 28, 5:58*pm, amit <amit.ko...@gmail.comwrote:
Hello group,

I'm uploading some image files such as jpeg, png and gif. However, I
must convert time to jpeg type. *I 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:

* * * * * if ($img_array_info[mime] == "image/jpg" {
* * * * * * * * * ...
* * * * * }

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 ) ||
(strcasecmp($array_img_information[mime], "image/jpeg") == 0 ) )
{
echo "<br>OK, jpeg file<br>";
}
else
{
echo "<br>$array_img_information[mime]<br>";
echo "<br>Not a jpeg file must conver it!<br>";

}

Is this a proper way or ....?

Thanks again.
Mar 29 '08 #2
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)
{
$cmd = 'convert ' . escapeshellarg($path) . ' ' .
escapeshellarg($newPath) . ' 2>&1';
exec($cmd, $output, $exitCode);
if ($exitCode != 0) {
throw new Exception("Command \"$cmd\" failed with " .
"exit code $exitCode: " . join("\n", $output));
}
}

$path = dirname(__FILE__) . '/img.gif';
$newPath = 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 <amit.ko...@gmail.comwrote:
On Mar 28, 5:58 pm, amit <amit.ko...@gmail.comwrote:
Hello group,
I'm uploading some image files such as jpeg, png and gif. However, I
must convert time to jpeg type. I 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:
if ($img_array_info[mime] == "image/jpg" {
...
}
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 ) ||
(strcasecmp($array_img_information[mime], "image/jpeg") == 0 ) )
{
echo "<br>OK, jpeg file<br>";}

else
{
echo "<br>$array_img_information[mime]<br>";
echo "<br>Not a jpeg file must conver it!<br>";

}

Is this a proper way or ....?

Thanks again.
Mar 29 '08 #3
On Mar 28, 7:10*pm, petersprc <peters...@gmail.comwrote:
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)
{
* $cmd = 'convert ' . escapeshellarg($path) . ' ' .
* * escapeshellarg($newPath) . ' 2>&1';
* exec($cmd, $output, $exitCode);
* if ($exitCode != 0) {
* * throw new Exception("Command \"$cmd\" failed with " .
* * * "exit code $exitCode: " . join("\n", $output));
* }

}

$path = dirname(__FILE__) . '/img.gif';
$newPath = 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<amit.ko...@gmail.comwrote:
On Mar 28, 5:58 pm,amit<amit.ko...@gmail.comwrote:
Hello group,
I'm uploading some image files such as jpeg, png and gif. However, I
must convert time to jpeg type. *I 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:
* * * * * if ($img_array_info[mime] == "image/jpg" {
* * * * * * * * * ...
* * * * * }
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 ) *||
(strcasecmp($array_img_information[mime], "image/jpeg") == 0 ) )
{
* *echo "<br>OK, jpeg file<br>";}
else
{
* *echo "<br>$array_img_information[mime]<br>";
* *echo "<br>Not a jpeg file must conver it!<br>";
}
Is this a proper way or ....?
Thanks again.- Hide quoted text -

- Show quoted text -

Thanks indeed for your help. Very nice function!

Regards,
Amit
Mar 31 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: clevariant | last post by:
Hello, I'm tasked with creating a WSDL file that is compatible with .NET's code gen' tool, wsdl.exe. I'm getting an error in the code output saying "Missing soap:body input binding", which...
1
by: Michael Loughry | last post by:
I'm writing a web application that fetches documents from the server and sends them to the client. I do this using the Response.BinaryWrite method. However, is there any way to detect the MIME...
5
by: splodge | last post by:
This may seem like a stupid question but I want to check before I go ahead and build this... I am working on a portal, part of which allows users to upload files. Part of the array within...
1
by: Datawright | last post by:
Apologies if this is a daft question but I'm new to c# and everything is strange to me. I have written a SOAP Extension class that intercepts a web service that returns MIME attachmernts as part...
60
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type?...
0
by: comp.lang.php | last post by:
if (!function_exists('mime_content_type_fileinfo')) { /** * Will use {@link http://us2.php.net/fileinfo FileInfo} functions provided within {@link http://pecl.php.net PECL} bundle to return mime...
1
by: comp.lang.php | last post by:
<pre> if (!function_exists('mime_content_type_fileinfo')) { /** * Will use {@link http://us2.php.net/fileinfo FileInfo} functions provided within {@link http://pecl.php.net PECL} bundle to return...
6
by: Mad Hatter | last post by:
Hi folks I'm a bit confused with an upload script that I've written. I want to be able to check the file type of an upload by checking the mime type but I'm not getting the results that I...
6
by: tinman77 | last post by:
Hello, I'm having a terrible time using the functions finfo_open and finfo_file. I'm using PHP 5 on IIS 5.1 and Windows XP. I have enabled php_mime_magic.dll and php_fileinfo.dll and also added...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.