473,715 Members | 3,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_inf o[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 1659
On Mar 28, 5:58*pm, amit <amit.ko...@gma il.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_inf o[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($ar ray_img_informa tion[mime], "image/jpg") == 0 ) ||
(strcasecmp($ar ray_img_informa tion[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("Comm and \"$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 imagecreatefrom gif then imagejpeg.

Regards,

John Peters

On Mar 28, 9:08 pm, amit <amit.ko...@gma il.comwrote:
On Mar 28, 5:58 pm, amit <amit.ko...@gma il.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_inf o[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($ar ray_img_informa tion[mime], "image/jpg") == 0 ) ||
(strcasecmp($ar ray_img_informa tion[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...@gmai l.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("Comm and \"$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 imagecreatefrom gif then imagejpeg.

Regards,

John Peters

On Mar 28, 9:08 pm,amit<amit.ko ...@gmail.comwr ote:
On Mar 28, 5:58 pm,amit<amit.ko ...@gmail.comwr ote:
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_inf o[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($ar ray_img_informa tion[mime], "image/jpg") == 0 ) *||
(strcasecmp($ar ray_img_informa tion[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
3240
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 seems to indicate it can't find the <soap:body> element where it's looking for it. We are using the extension <mime:multipartRelated> to define some SOAP attachements in our interface, and the <soap:body> element is inside a subelement of that (per...
1
3044
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 type of a given file? Or a catch-all MIME type I could use? These files will likely mainly be word and pdf documents, but they can conceivably be anything.
5
3002
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 $_FILES superglobal gives the mime type for the file. Is this 100% reliable / accurate? If the mime type says the file type is jpeg is it always right? Two reasons I want to know: 1. Certain types of files mustn't be uploaded, .exe files for example....
1
1656
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 of a multipart. I have split the MIME into strings which I write to a file via a BinaryWriter. All this of course gives me is exactly the same content as the string. My question is how do I take a string containing MIME and create a file that...
60
8015
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I prompt a "Save As" dialog for an accepted mime type? ----------------------------------------------------------------------- It is not possible with client-side JavaScript. Some browsers accept the Content-Disposition header, but this must be added by the server. Taking the form:- ` Content-Disposition: attachment; filename=filename.ext `
0
1786
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 type * * @param string $file * @return string $mime_type * @see mime_content_type */
1
3533
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 mime type * * @param string $file * @return string $mime_type * @see mime_content_type
6
6252
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 thought I should. According to what I've read .zip files should return something like 'application/zip' or 'application/x-zip-compressed', RAR should return 'application/x-rar-compressed' but both return 'application/octet-stream'. I'm getting the...
6
6504
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 the lines mime_magic.debug = Off and mime_magic.magicfile = "C:\Program Files\PHP\extras\magic.mime". Now my phpinfo() says fileinfo support is enabled and mime_magic support is enabled. However, I keep getting this error:
0
8821
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8718
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9103
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9047
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7973
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4477
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.