Download the PHP package rosell-dk/image-mime-type-guesser without Composer

On this page you can find all versions of the php package rosell-dk/image-mime-type-guesser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package image-mime-type-guesser

image-mime-type-guesser

Latest Stable Version Minimum PHP Version Build Status Coverage Software License Monthly Downloads Dependents

Detect / guess mime type of an image

Do you need to determine if a file is an image?
And perhaps you also want to know the mime type of the image?

– You come to the right library.

Ok, actually the library cannot offer mime type detection for images which works on all platforms, but it can try a whole stack of methods and optionally fall back to guess from the file extension.

The stack of detect methods are currently (and in that order):

Note that all these methods except the signature sniffer relies on the mime type mapping on the server (the mime.types file in Apache). If the server doesn't know about a certain mime type, it will not be detected. This does however not mean that the methods relies on the file extension. A png file renamed to "png.jpeg" will be correctly identified as image/png.

Besides the detection methods, the library also comes with a method for mapping file extension to mime type. It is rather limited, though.

Installation

Install with composer:

Usage

To detect the mime type of a file, use ImageMimeTypeGuesser::detect($filePath). It returns the mime-type, if the file is recognized as an image. false is returned if it is not recognized as an image. null is returned if the mime type could not be determined (ie due to none of the methods being available).

Example:

For convenience, you can use detectIsIn method to test if a detection is in a list of mimetypes.

The detect method does not resort to mapping from file extension. In most cases you do not want to do that. In some cases it can be insecure to do that. For example, if you want to prevent a user from uploading executable files, you probably do not want to allow her to upload executable files with innocent looking file extenions, such as "evil-exe.jpg".

In some cases, though, you simply want a best guess, and in that case, falling back to mapping from file extension makes sense. In that case, you can use the guess method instead of the detect method. Or you can use lenientGuess. Lenient guess is even more slacky and will turn to mapping not only when dectect return null, but even when it returns false.

Warning: Beware that guessing from file extension is unsuited when your aim is to protect the server from harmful uploads.

Notice: Only a limited set of image extensions is recognized by the extension to mimetype mapper - namely the following: { apng, avif, bmp, gif, ico, jpg, jpeg, png, tif, tiff, webp, svg }. If you need some other specifically, feel free to add a PR, or ask me to do it by creating an issue.

Example:

The guess functions also have convenience methods for testing against a list of mime types. They are called ImageMimeTypeGuesser::guessIsIn and ImageMimeTypeGuesser::lenientGuessIsIn.

Example:

Alternatives

Other sniffers:

Do you like what I do?

Perhaps you want to support my work, so I can continue doing it :)


All versions of image-mime-type-guesser with dependencies

PHP Build Version
Package Version
Requires php Version ^5.6 | ^7.0 | ^8.0
rosell-dk/image-mime-type-sniffer Version ^1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rosell-dk/image-mime-type-guesser contains the following files

Loading the files please wait ....