Rotation and Rolling

PHP ImageMagick – Rotation and Rolling ”; Previous Next In this chapter, you will be learning to rotate and roll images using the inbuilt functions of Imagemagick. Rotating an image Imagemagick has provided an inbuilt function ‘rotateImage()’ which is used to rotate the images according to the angle specified. This function takes an image as input, applied this function, and rotates the image and the rotated image is obtained as output. Syntax public Imagick::rotateImage(mixed $background, float $degrees): bool This function has 2 parameters: background and degrees. ‘Background’ specifies the background color and ‘degrees’ is a float value that specifies the rotation angle, in degrees. The image is rotated clockwise at the specified angle. Example In the below example, a new imagick object is created at first and an image is taken as input. ‘rotateImage()’ function is applied on that image and the image is rotated to that specified angle. The rotated image is obtained as output with the help of ‘writeImage()’ function. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.png”); $image->rotateImage(”black”, 40); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/rotateImage.png”); ?> Assume that the following is the input image (image.png) in the program − Output Rolling an image Did you ever observe the process of rolling something? That thing that you are rolling is moved by revolving or turning it over and over. Rolling an image also means the same. It is nothing but offsetting an image. For this purpose, ImageMagick has provided an inbuilt function ‘rollImage()’ which takes an image as input, rolls the image and the rolled image is obtained as output. Syntax public Imagick::rollImage(int $x, int $y): bool This function takes 2 parameters: x and y. ‘x’ and ‘y’ are integer values, and they specify the x offset and y offset respectively. Example In this example, an image is taken as input by creating a new imagick object. Then, ‘rollImage()’ function is applied on it with the help of specified a and y offsets (x=30, y=40). The rolled image is obtained as output. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.png”); $image->rollImage (300, 40); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/rollImage.png”); ?> Assume that the following is the input image (image.png) in the program − Output Print Page Previous Next Advertisements ”;

PHP ImageMagick – Resources

PHP ImageMagick – Useful Resources ”; Previous Next The following resources contain additional information on PHP ImageMagick. Please use them to get more in-depth knowledge on this. Useful Video Courses PHP Programming Online Training Most Popular 46 Lectures 9 hours Tutorialspoint More Detail PHP from Scratch Full Course 18 Lectures 1 hours Nivedita Jain More Detail Full Stack Web Development – HTML, CSS, JavaScript, PHP, ELIXIR 55 Lectures 6 hours Pranjal Srivastava, Harshit Srivastava More Detail Java, PHP and MySQL Course Bundle 53 Lectures 6 hours Harshit Srivastava More Detail Learn PHP – For Beginners 31 Lectures 1.5 hours YouAccel More Detail JavaScript, Bootstrap, and PHP – Training for Beginners 117 Lectures 5.5 hours YouAccel More Detail Print Page Previous Next Advertisements ”;

Editing TheAppearance

PHP ImageMagick – Editing TheAppearance ”; Previous Next In this chapter, you will explore how to use Imagemagick”s built-in functions to edit an image. You”ll learn how to create a faded and rounded look on the edges of your image, wrap it in a parallelogram shape, and even simulate a polaroid effect. Vignette Image The word ‘vignette’ means a small photograph or image which has a faded appearance with its background and doesn’t have a definite border. Having this effect highlights certain aspects of the image. So, to get images in this filter, Imagemagick provided an inbuilt function ‘vignetteImage()’. This function takes an image as input, applies a vignette filter, and obtained image has its borders blurred. Syntax public Imagick::vignetteImage(float $blackPoint, float $whitePoint, int $x, int $y): bool This function has 4 parameters: blackpoint, whitepoint, x, and y. ‘Blackpoint’ and ‘whitepoint’ are float values. ‘x’ is an integer value that specifies the ‘x’ offset of the ellipse and ‘y’ is an integer value that specifies the ‘y’ offset of the ellipse. Example To have a better understanding of ‘vignetteImage()’ function, look at the below example. An imagick object is created at first and an image is taken as input. Then, ‘vignetteImage’ function is applied with all the parameters specified (blackpoint=30, whitepoint=10, x=40, y=20). Finally, the output is obtained using ‘writeImage()’ function. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.png”); $image->vignetteImage(30, 10, 40, 20); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/vignetteImage.png”); ?> Assume that the following is the input image (image.png) in the program − Output Rounding corners There is a basic belief that rounded corners are easier on the eyes. That is, they are suitable for the natural movement of the head and eyes respectively. Rounding image corners can also make the image look more organized and neater. To round the corners of an image, there are an inbuilt function ‘roundCorners()’ provided by Imagemagick. This function takes an image as input, rounds the corners, and produces that image as output. Syntax public Imagick::roundCorners( float $x_rounding, float $y_rounding, float $stroke_width =10, float $displace =5, float $size_correction =-6 ): bool This function has 5 parameters: x_rounding, y_rounding, strike_width, displace, and size_correction. ‘x_rounding’ and ‘y_rounding’ are float values and they control the amount of rounding. ‘stroke_width’, ‘displace’, and ‘size-correction’ are also float values which are used to fine-tune the rounding process. Example From this example, you will be able to clearly understand the usage of this function. The image is taken as input at first by creating a new Imagick object. ‘roundCorners()’ function is applied to that image with the help of the parameters specified (x_rounding=20, y_rounding=20, stroke-width=5, displace=5, size-correction=-10). Then, the output image is obtained using the function ‘writeImage()’. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/imagee.png”); $image->roundCorners(20, 20, 5, 5, -10); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/roundCornerImage.png”); ?> Assume that the following is the input image (image.png) in the program − Output Polaroid Image In this chapter, you will be learning to simulate the polaroid picture. A polaroid picture is a picture that is taken by a polaroid camera. It is a type of camera that takes a picture and prints it after a few seconds. It is a type of instant print and has a special type of film holder. For simulating a polaroid image, Imagemagick has provided an inbuilt function ‘polaroidImage()’. Syntax public Imagick::polaroidImage(ImagickDraw $properties, float $angle): bool This function takes in 2 parameters: properties and angle. ‘Properties’ specifies the polaroid properties and ‘angle’ specifies the polaroid angle in float value. Example In this example, you create a new imagick object and takes an image as input. Then, apply ‘polaroidImage()’ function on that image by specifying the parameters. The polaroid image is obtained as output. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/imagee.png”); $image->polaroidImage(new ImagickDraw(), 30); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/polaroidImage.png”); ?> Assume that the following is the input image (image.png) in the program − Output Creation of Parallelogram In this section, you will be learning about the function ‘shearImage()’. It is an inbuilt function provided by Imagemagick. The functionality of this is to create a parallelogram. This function takes an image as input and shears the image on the X and Y axis to create a parallelogram and adds a background color. Syntax public Imagick::shearImage(mixed $background, float $x_shear, float $y_shear): bool This function takes in 3 parameters: background, x_shear, and y_shear. ‘Background’ specifies the background color, ‘x_shear’ specifies the number of degrees to shear on the X-axis, and ‘y_shear’ specifies the number of degrees to shear on the Y-axis. Example In the below example, the image is taken as input, and ‘shearImage ()’ function is applied on that image. It takes in 3 parameters (background color= rgb (100, 200, 150), x_shear=10 and y_shear=10). The obtained output is displayed using the function ‘writeImage ()’. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.png”); $image->shearImage(”rgb(100, 200, 150)”, 10, 10); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/shearImage.png”); ?> Assume that the following is the input image (image.png) in the program − Output Print Page Previous Next Advertisements ”;

PHP ImageMagick – Introduction

PHP ImageMagick – Introduction ”; Previous Next We know that images are an easy way to improve the user experience of any website. Many experiments proved that our brain could interpret images much quicker than text. They also help in attracting attention and triggering emotions. When it comes to presenting important information, images can be of great value. How can we create or edit images dynamically, making them suitable for web applications? ”ImageMagick” does that! What is ImageMagick? ImageMagick is a freely available robust collection of tools and libraries to perform many operations on digital images. It is a software suite to read, create, edit, compose, convert, and write images in a variety of formats. These formats include DPX, EXR, GIF, JPG, JPEG, PNG, TIFF, etc. (over 200 formats). These operations are available from the command line, or C, C++, Perl, Java, PHP, or Python programming languages. In this tutorial, we will be learning about ImageMagick in PHP. What is PHP? PHP stands for Hypertext pre-processor. It is a server-side scripting language that is embedded in HTML. It contains various built-in functions which allow for fast development. These scripts are executed on the server and the software is free to download and use. What is ImageMagick in PHP? ImageMagick in PHP is a native extension that does all the operations on images. Operations also include resizing, flipping, mirroring, rotating, distorting, transforming images, adjusting image colors, or even drawing text, lines, polygons, ellipses, and curves. It is free software delivered as a ready-to-run binary distribution or as source code that you may use, copy, modify, and distribute in both open and proprietary applications. It utilizes multiple computational threads to increase performance and can read, process, or write mega-, giga-, or tera-pixel image sizes. It runs on Linux, Windows, Mac OS X, iOS, Android OS, and others. Installation and Configuring As we know that PHP is a server-side scripting language, using any web servers like Apache, Nginx, etc. to run PHP scripts would be preferable. This allows you to run the PHP scripts from your browser. There is also another way to execute the PHP scripts which is using the command line. This doesn’t require any web server to be installed. In this tutorial, you will be learning to implement ImageMagick features using the Apache server. For this, we install XAMPP. XAMPP stands for cross-platform, Apache, Maria DB, PHP, Perl. It is a free and open-source cross-platform web server solution stack package developed by Apache Friends, consisting mainly of the Apache HTTP server, Maria DB, and interpreters for scripts written in PHP and Perl programming languages. Installing XAMPP: In this section, you will be able to learn the step-by-step process of installing XAMPP. Step 1 − Open this website − https://www.apachefriends.org Step 2 − Install the latest version of XAMPP available there which is suitable for your operating system (Windows/Linux/IOS). Step 3 − The file downloaded will be something like ”xampp-windows-x64-7.4.27-2-VC15-installer’. Step 4 − Run the downloaded file. You get some warning, click ”OK”. Step 5 − The below screen appears, click ”Next”. Step 6 − Select Apache, MySQL, PHP, and phpMyAdmin. and click ”Next”. Step 7 − In this step, select any specific folder, or else, you can leave it as it is(default). Click ”Next”. Step 8 − In the next step, the files will be unpacked automatically. After the process completes, click ”Next”. Step 9 − After it completes 100%, click ”Next”. Step 10 − Now, there appears a dialog box which contains ”Completing the XAMPP setup wizard”, then click ”Finish”. Installing ImageMagick In this section, you will learn to install the ImageMagick extension and installer in PHP. Step 1 − Open the website https://mlocati.github.io Step 2 − Download both the ImageMagick extension and installer according to your PHP configuration, architecture, and thread-safety of your XAMPP version. Downloaded installer file will be in the form ”ImageMagick-7.1.0-18-vc15-x64.zip” Downloaded ImageMagick extension is in the form ”php-imagick-3.7.0-7.4-ts-vc15-x64.zip”. Step 3 − Extract all the files from the extension file downloaded (from (b)). And from those files, copy the ‘php_imagemagick.dll’ file. Step 4 − Paste the file into the ‘ext’ directory of your PHP installation. Step 5 − Extract all files from the installer file downloaded (from (a)). From that, copy all files starting with CORE_DL / IM_MOP_RL/FILTER which are DLL files. The files start from ‘CORE_RL_bzlib_.dll’ as shown in the below image. Choose the files until where they end with ‘IM_MOD_RL_yuv_.dll’. Step 6 − Paste those files to the PHP root directory where there is ”php.exe”. Step 7 − Now, go to XAMPP Control Panel. Stop Apache. Step 8 − Click ”Config” and select PHP (php.ini) file. Step 9 − In that file, find ”extensions” in that code. After ”extension=php_ftp.dll” line, type ”extension=php_imagick.dll”. Save the file. Step 10 − Restart Apache. Step 11 − Installation completed. Verification Before directly jumping to the execution part, let us first check whether Imagemagick is properly installed in PHP on your system. For this, follow the below steps. Step 1 − Go to the browser and click ”localhost”. Step 2 − Go to ”phpinfo” which is in the top right corner. Step 3 − Search for Imagick. The screen must appear as shown below. Step 4 − If it appears, the Imagick setup is successfully done. This package contains the Imagick module version, Imagick classes, release dates, and all the supported formats. Print Page Previous Next Advertisements ”;

Securing The Images

PHP ImageMagick – Securing The Images ”; Previous Next In this chapter, you will be learning to secure the images so that only the sender and the intended receiver get to see the images on the web pages. PHP Imagemagick provides image processing and manipulation, allowing you to protect your images from theft or unauthorized use. Now, we will discuss the features of PHP Imagemagick and how they can help you keep your images safe. Enciphering an Image The inbuilt function named ‘encipherImage()’ in Imagemagick, helps in enciphering the images. Converting the plain pixels image to the enciphered pixels is the process that happens in this function. The enciphered image can be viewed only by the viewer who can decipher the image using the key is given (‘passphrase’). Syntax public Imagick::encipherImage(string $passphrase): bool This function takes one parameter ‘passphrase’ which acts as a key to encrypt and decrypt images. It takes an image as input and enciphers the image using the passphrase and produces the enciphered image as output. Example In the below example, the implementation of ‘encipherImage()’ function is shown. Firstly, a new imagick object must be created and an image is taken as input. ‘Passphrase’ is defined which is a string that is passed as a parameter. Then, ‘encipherImage()’ function is applied with the help of the passphrase and the enciphered image is obtained as output. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.jpeg”); $passphrase=”Tutorials Point”; $image->encipherImage($passphrase); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/encipherImage.png”); ?> Assume that the following is the input image (image.jpeg) in the program − Output Deciphering the Image Imagemagick has provided an inbuilt function ‘decipherImage()’ which helps to decipher the image. The process of converting the encrypted image to a plain image is called deciphering an image. This function takes the enciphered image as input, converts that image to a plain image using the passphrase, and produces the plain image as output. Syntax public Imagick::decipherImage(string $passphrase): bool This function takes the ‘passphrase’ as a parameter. It helps to decipher the image. Example The following example shows how to implement the ”decipherImage()” function. To begin, create a new Imagick object and pass an image as input. You will also need to define a passphrase string which is passed as a parameter. Finally, use the ”decipherImage()” function with your passphrase to obtain a deciphered image as output. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/encipherImage.png”); $passphrase=”Tutorials Point”; $image->decipherImage($passphrase); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/decipherImage.png”); ?> Assume that the following is the input image (encipherImage.png) in the program − Output Print Page Previous Next Advertisements ”;