Home / PHP / Image conversion using PHP – ImageMagick

Image conversion using PHP – ImageMagick

In this tutorial we will be learning Image Conversion using ImageMagick. ImageMagick is a very effective PHP native extension that has capacity to create and modify images over 100 image file formats. There are several PHP libraries that does the job of creating and modifying images nevertheless ImageMagick outsmarts them all with its intelligent short predefined functions. This native PHP extension is also capable of creating and modifying rare extensions like DICOM (Medical Imaging) and its kind also.

Requirements: Image Conversion – ImageMagick

* ImageMagick should be installed on your local server if you are testing locally.
* If you are on a shared hosting you can ask your Host to activate ImageMagick extension.

The Style

The design is very straight forward. I have used Bootstrap CSS for styling the elements so as to minimize the time consumption. You can play with your own styles and colors. The upload button has been styled with custom CSS which is shown below

Mark Up

I have setup two elements, Select box and Input File. File types have been predefined but you can bring in data from database dynamically.

Having the design ready with CSS and HTML let us jump to the validation.

Validation

First we check if a file is uploaded by the user and submit the form if file type is selected else show the select box to the user.

Following are the functions called in the above JavaScript

We have set up the front-end and validation part can be checked at this stage. The final step is to set up the file upload script.

upload.php

I’m defining two functions here success() and emptyfile()

Now that we have written the functions, we need to call them based on the flag value,

That’s it! We are now ready to test the conversion… You should not miss out trying PDF format!

Download

About Ashik

I am a Full Stack Developer and love to work on APIs and Apps. Hardcore lover of Ionic and Laravel <3

Check Also

Telegram Bot API – Search wordpress posts

In this tutorial we will search wordpress posts and list them to the user. If …

  • xcept

    Quick question, where do you set your “tmp” path for the files which fail due to lets say conversion file format or what ever, their essentially uploaded to the server…or?

Do you wan't to get notified?

I will not spam your inbox. I will only send email whenever I publish a new article or to share information about technology

You have Successfully Subscribed!