Ruby – Environment Setup ”; Previous Next Local Environment Setup If you are still willing to set up your environment for Ruby programming language, then let”s proceed. This tutorial will teach you all the important topics related to environment setup. We would recommend you to go through the following topics first and then proceed further − Ruby Installation on Linux/Unix − If you are planning to have your development environment on Linux/Unix Machine, then go through this chapter. Ruby Installation on Windows − If you are planning to have your development environment on Windows Machine, then go through this chapter. Ruby Command Line Options − This chapter list out all the command line options, which you can use along with Ruby interpreter. Ruby Environment Variables − This chapter has a list of all the important environment variables to be set to make Ruby Interpreter works. Popular Ruby Editors To write your Ruby programs, you will need an editor − If you are working on Windows machine, then you can use any simple text editor like Notepad or Edit plus. VIM (Vi IMproved) is a very simple text editor. This is available on almost all Unix machines and now Windows as well. Otherwise, your can use your favorite vi editor to write Ruby programs. RubyWin is a Ruby Integrated Development Environment (IDE) for Windows. Ruby Development Environment (RDE) is also a very good IDE for windows users. Interactive Ruby (IRb) Interactive Ruby (IRb) provides a shell for experimentation. Within the IRb shell, you can immediately view expression results, line by line. This tool comes along with Ruby installation so you have nothing to do extra to have IRb working. Just type irb at your command prompt and an Interactive Ruby Session will start as given below − $irb irb 0.6.1(99/09/16) irb(main):001:0> def hello irb(main):002:1> out = “Hello World” irb(main):003:1> puts out irb(main):004:1> end nil irb(main):005:0> hello Hello World nil irb(main):006:0> Do not worry about what we did here. You will learn all these steps in subsequent chapters. What is Next? We assume now you have a working Ruby Environment and you are ready to write the first Ruby Program. The next chapter will teach you how to write Ruby programs. Print Page Previous Next Advertisements ”;
Category: Computer Programming
Ruby – Variables
Ruby – Variables, Constants and Literals ”; Previous Next Variables are the memory locations, which hold any data to be used by any program. There are five types of variables supported by Ruby. You already have gone through a small description of these variables in the previous chapter as well. These five types of variables are explained in this chapter. Ruby Global Variables Global variables begin with $. Uninitialized global variables have the value nil and produce warnings with the -w option. Assignment to global variables alters the global status. It is not recommended to use global variables. They make programs cryptic. Here is an example showing the usage of global variable. Live Demo #!/usr/bin/ruby $global_variable = 10 class Class1 def print_global puts “Global variable in Class1 is #$global_variable” end end class Class2 def print_global puts “Global variable in Class2 is #$global_variable” end end class1obj = Class1.new class1obj.print_global class2obj = Class2.new class2obj.print_global Here $global_variable is a global variable. This will produce the following result − NOTE − In Ruby, you CAN access value of any variable or constant by putting a hash (#) character just before that variable or constant. Global variable in Class1 is 10 Global variable in Class2 is 10 Ruby Instance Variables Instance variables begin with @. Uninitialized instance variables have the value nil and produce warnings with the -w option. Here is an example showing the usage of Instance Variables. Live Demo #!/usr/bin/ruby class Customer def initialize(id, name, addr) @cust_id = id @cust_name = name @cust_addr = addr end def display_details() puts “Customer id #@cust_id” puts “Customer name #@cust_name” puts “Customer address #@cust_addr” end end # Create Objects cust1 = Customer.new(“1”, “John”, “Wisdom Apartments, Ludhiya”) cust2 = Customer.new(“2”, “Poul”, “New Empire road, Khandala”) # Call Methods cust1.display_details() cust2.display_details() Here, @cust_id, @cust_name and @cust_addr are instance variables. This will produce the following result − Customer id 1 Customer name John Customer address Wisdom Apartments, Ludhiya Customer id 2 Customer name Poul Customer address New Empire road, Khandala Ruby Class Variables Class variables begin with @@ and must be initialized before they can be used in method definitions. Referencing an uninitialized class variable produces an error. Class variables are shared among descendants of the class or module in which the class variables are defined. Overriding class variables produce warnings with the -w option. Here is an example showing the usage of class variable − Live Demo #!/usr/bin/ruby class Customer @@no_of_customers = 0 def initialize(id, name, addr) @cust_id = id @cust_name = name @cust_addr = addr end def display_details() puts “Customer id #@cust_id” puts “Customer name #@cust_name” puts “Customer address #@cust_addr” end def total_no_of_customers() @@no_of_customers += 1 puts “Total number of customers: #@@no_of_customers” end end # Create Objects cust1 = Customer.new(“1”, “John”, “Wisdom Apartments, Ludhiya”) cust2 = Customer.new(“2”, “Poul”, “New Empire road, Khandala”) # Call Methods cust1.total_no_of_customers() cust2.total_no_of_customers() Here @@no_of_customers is a class variable. This will produce the following result − Total number of customers: 1 Total number of customers: 2 Ruby Local Variables Local variables begin with a lowercase letter or _. The scope of a local variable ranges from class, module, def, or do to the corresponding end or from a block”s opening brace to its close brace {}. When an uninitialized local variable is referenced, it is interpreted as a call to a method that has no arguments. Assignment to uninitialized local variables also serves as variable declaration. The variables start to exist until the end of the current scope is reached. The lifetime of local variables is determined when Ruby parses the program. In the above example, local variables are id, name and addr. Ruby Constants Constants begin with an uppercase letter. Constants defined within a class or module can be accessed from within that class or module, and those defined outside a class or module can be accessed globally. Constants may not be defined within methods. Referencing an uninitialized constant produces an error. Making an assignment to a constant that is already initialized produces a warning. Live Demo #!/usr/bin/ruby class Example VAR1 = 100 VAR2 = 200 def show puts “Value of first Constant is #{VAR1}” puts “Value of second Constant is #{VAR2}” end end # Create Objects object = Example.new() object.show Here VAR1 and VAR2 are constants. This will produce the following result − Value of first Constant is 100 Value of second Constant is 200 Ruby Pseudo-Variables They are special variables that have the appearance of local variables but behave like constants. You cannot assign any value to these variables. self − The receiver object of the current method. true − Value representing true. false − Value representing false. nil − Value representing undefined. __FILE__ − The name of the current source file. __LINE__ − The current line number in the source file. Ruby Basic Literals The rules Ruby uses for literals are simple and intuitive. This section explains all basic Ruby Literals. Integer Numbers Ruby supports integer numbers. An integer number can range from -230 to 230-1 or -262 to 262-1. Integers within this range are objects of class Fixnum and integers outside this range are stored in objects of class Bignum. You write integers using an optional leading sign, an optional base indicator (0 for octal, 0x for hex, or 0b for binary), followed by a string of digits in the appropriate base. Underscore characters are ignored in the digit string. You can also get the integer value, corresponding to an ASCII character or escape the sequence by preceding it with a question mark. Example 123 # Fixnum decimal 1_234 # Fixnum decimal with underline -500 # Negative Fixnum 0377 # octal 0xff # hexadecimal 0b1011 # binary ?a # character code for ”a” ?n # code for a newline (0x0a) 12345678901234567890 # Bignum NOTE − Class and Objects are explained in a separate chapter of this tutorial. Floating Numbers Ruby supports floating numbers. They are also numbers but with decimals. Floating-point numbers are objects of class Float and can be any of the following −
Ruby – Syntax
Ruby – Syntax ”; Previous Next Let us write a simple program in ruby. All ruby files will have extension .rb. So, put the following source code in a test.rb file. Live Demo #!/usr/bin/ruby -w puts “Hello, Ruby!”; Here, we assumed that you have Ruby interpreter available in /usr/bin directory. Now, try to run this program as follows − $ ruby test.rb This will produce the following result − Hello, Ruby! You have seen a simple Ruby program, now let us see a few basic concepts related to Ruby Syntax. Whitespace in Ruby Program Whitespace characters such as spaces and tabs are generally ignored in Ruby code, except when they appear in strings. Sometimes, however, they are used to interpret ambiguous statements. Interpretations of this sort produce warnings when the -w option is enabled. Example a + b is interpreted as a+b ( Here a is a local variable) a +b is interpreted as a(+b) ( Here a is a method call) Line Endings in Ruby Program Ruby interprets semicolons and newline characters as the ending of a statement. However, if Ruby encounters operators, such as +, −, or backslash at the end of a line, they indicate the continuation of a statement. Ruby Identifiers Identifiers are names of variables, constants, and methods. Ruby identifiers are case sensitive. It means Ram and RAM are two different identifiers in Ruby. Ruby identifier names may consist of alphanumeric characters and the underscore character ( _ ). Reserved Words The following list shows the reserved words in Ruby. These reserved words may not be used as constant or variable names. They can, however, be used as method names. BEGIN do next then END else nil true alias elsif not undef and end or unless begin ensure redo until break false rescue when case for retry while class if return while def in self __FILE__ defined? module super __LINE__ Here Document in Ruby “Here Document” refers to build strings from multiple lines. Following a << you can specify a string or an identifier to terminate the string literal, and all lines following the current line up to the terminator are the value of the string. If the terminator is quoted, the type of quotes determines the type of the line-oriented string literal. Notice there must be no space between << and the terminator. Here are different examples − Live Demo #!/usr/bin/ruby -w print <<EOF This is the first way of creating here document ie. multiple line string. EOF print <<“EOF”; # same as above This is the second way of creating here document ie. multiple line string. EOF print <<`EOC` # execute commands echo hi there echo lo there EOC print <<“foo”, <<“bar” # you can stack them I said foo. foo I said bar. bar This will produce the following result − This is the first way of creating her document ie. multiple line string. This is the second way of creating her document ie. multiple line string. hi there lo there I said foo. I said bar. Ruby BEGIN Statement Syntax BEGIN { code } Declares code to be called before the program is run. Example Live Demo #!/usr/bin/ruby puts “This is main Ruby Program” BEGIN { puts “Initializing Ruby Program” } This will produce the following result − Initializing Ruby Program This is main Ruby Program Ruby END Statement Syntax END { code } Declares code to be called at the end of the program. Example Live Demo #!/usr/bin/ruby puts “This is main Ruby Program” END { puts “Terminating Ruby Program” } BEGIN { puts “Initializing Ruby Program” } This will produce the following result − Initializing Ruby Program This is main Ruby Program Terminating Ruby Program Ruby Comments A comment hides a line, part of a line, or several lines from the Ruby interpreter. You can use the hash character (#) at the beginning of a line − # I am a comment. Just ignore me. Or, a comment may be on the same line after a statement or expression − name = “Madisetti” # This is again comment You can comment multiple lines as follows − # This is a comment. # This is a comment, too. # This is a comment, too. # I said that already. Here is another form. This block comment conceals several lines from the interpreter with =begin/=end − =begin This is a comment. This is a comment, too. This is a comment, too. I said that already. =end Print Page Previous Next Advertisements ”;
Ruby – Overview
Ruby – Overview ”; Previous Next Ruby is a pure object-oriented programming language. It was created in 1993 by Yukihiro Matsumoto of Japan. You can find the name Yukihiro Matsumoto on the Ruby mailing list at www.ruby-lang.org. Matsumoto is also known as Matz in the Ruby community. Ruby is “A Programmer”s Best Friend”. Ruby has features that are similar to those of Smalltalk, Perl, and Python. Perl, Python, and Smalltalk are scripting languages. Smalltalk is a true object-oriented language. Ruby, like Smalltalk, is a perfect object-oriented language. Using Ruby syntax is much easier than using Smalltalk syntax. Features of Ruby Ruby is an open-source and is freely available on the Web, but it is subject to a license. Ruby is a general-purpose, interpreted programming language. Ruby is a true object-oriented programming language. Ruby is a server-side scripting language similar to Python and PERL. Ruby can be used to write Common Gateway Interface (CGI) scripts. Ruby can be embedded into Hypertext Markup Language (HTML). Ruby has a clean and easy syntax that allows a new developer to learn very quickly and easily. Ruby has similar syntax to that of many programming languages such as C++ and Perl. Ruby is very much scalable and big programs written in Ruby are easily maintainable. Ruby can be used for developing Internet and intranet applications. Ruby can be installed in Windows and POSIX environments. Ruby support many GUI tools such as Tcl/Tk, GTK, and OpenGL. Ruby can easily be connected to DB2, MySQL, Oracle, and Sybase. Ruby has a rich set of built-in functions, which can be used directly into Ruby scripts. Tools You Will Need For performing the examples discussed in this tutorial, you will need a latest computer like Intel Core i3 or i5 with a minimum of 2GB of RAM (4GB of RAM recommended). You also will need the following software − Linux or Windows 95/98/2000/NT or Windows 7 operating system. Apache 1.3.19-5 Web server. Internet Explorer 5.0 or above Web browser. Ruby 1.8.5 This tutorial will provide the necessary skills to create GUI, networking, and Web applications using Ruby. It also will talk about extending and embedding Ruby applications. What is Next? The next chapter guides you to where you can obtain Ruby and its documentation. Finally, it instructs you on how to install Ruby and prepare an environment to develop Ruby applications. Print Page Previous Next Advertisements ”;
Contrast & Brightness
PHP ImageMagick – Contrast & Brightness ”; Previous Next Different types of moods can be conveyed in images with the help of contrast. The term ‘contrast’ refers to the amount of color or grayscale differentiation. Images with higher contrast levels generally display a greater degree of color or grayscale variation than those of lower contrast. In this chapter, you will be learning about changing and adjusting the contrast and brightness. Changing the Contrast In this section, you will be learning about the process of changing the contrast. This can be done using a method called ‘contrastImage()’ which is provided by Imagemagick. It helps to enhance the differences between lighter and darker elements of the image. Syntax public Imagick::contrastImage(bool $sharpen): bool This method contains a single parameter which is ‘sharpen’. It is a boolean value that specifies the sharpen value. This method takes an image as an input and gives out the image after changing its contrast as output. Example In the below example, new imagick object is created and the input image is taken. Then, the contrastImage() function is applied on that image. Finally, the output image is obtained in the format ‘contrastImage.png’. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.jpeg”); $image->contrastImage(true); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/contrastImage.png”); ?> Assume that the following is the input image (image.jpeg) in the program − Output Changing the Brightness ImageMagick provided a method called ‘brightnessContrastImage()’ which changes the brightness and contrast of an image. It converts the brightness and contrast parameters into slope and intercept and calls a polynomial function to apply to the image. Syntax Public Imagick::brightnessContrastImage(float $brightness, float $contrast, int $channel=Imagick::CHANNEL_DEFAULT):bool This method contains 3 parameters which are brightness, contrast, and channel. ‘Brightness’ is used to store the value of brightness, ‘contrast’ is used to store the value of the contrast of the image, and ‘channel’ is used to store the value of the channel. The output obtained is an image with added brightness and contrast. Example In the below example, a new imagick object is created and the input image is taken. Then, the ‘brightnessContrastImage()’ function with parameters (brightness=15, contrast=20) is applied on that image. Finally, the output image is obtained in the format ‘brightnessContrastImage.png’. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image5.jpeg”); $image->brightnessContrastImage(15,50); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/brightnessContrastImage.png”); ?> Assume that the following is the input image (image5.jpeg) in the program − Output Enhance the Contrast Enhancement is the process of improving quality of an image. To enhance the contrast, Imagemagick has provided a method ‘contrastStretchImage()’ which enhances the contrast of the color image by adjusting the pixels” color to span the entire range of colors available. Syntax public Imagick::contrastStretchImage(float $black_point, float $white_point, int $channel = Imagick::CHANNEL_DEFAULT): bool This method has three parameters which are black_point, white_point, and channel. ‘Black_point’ specifies the black point, ‘white_point’ specifies the white point and’ channel’ provides any channel constant that is valid for your channel mode. Example In the below example, a new Imagick object is created and the input image is taken. Then, the ‘contrastStretchImage()’ function with parameters(black_point=1000, white_point=5000) is applied on that image. Finally, the output image is obtained in the format ‘contrastStretchImage.png’. This method has three parameters which are black_point, white_point, and channel. ‘Black_point’ specifies the black point, ‘white_point’ specifies the white point and’ channel’ provides any channel constant that is valid for your channel mode. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.jpeg”); $image->contrastStretchImage(1000, 5000); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/contrastStretchImage.png”); ?> Assume that the following is the input image (image.jpeg) in the program − Output Print Page Previous Next Advertisements ”;
Image Tiling
PHP ImageMagick – Image Tiling ”; Previous Next In this chapter, you will be learning to tile a texture image repeatedly. Tiling a texture image is the process of creating a pattern in which the texture image is repeated which is in the form of tiles. With ImageMagick, you can easily tile an image into equal-sized pieces. You can also adjust the size and orientation of each piece, allowing you to customize your tiled image however you want. In this tutorial, we”ll explain how to use PHP ImageMagick”s Image tile to achieve perfect results in creating stunningly beautiful tiled images! Syntax Imagick::textureImage(Imagick $texture_wand): Imagick This function consists of one parameter ‘texture_wand’. It is an Imagick object that is used as a texture image. The below example is a program to tile the images. This program has a few additional are used other than ‘textureImage()’. New image creation − It involves the creation of a new image using the function ‘newImage()’ which takes the column size and row size as arguments. Hence, an image with those measurements is created. Scaling the image − A function ‘scaleImage()’ is used to scale the image to a particular dimension and the image is shortened with those dimensions and hence can be tiled on the new image that we created. This function takes the image as input and the output obtained is the image that contains the pattern of tiles of texture images. Example Below example shows the implementation of the ‘textureImage()’ function. Here, a new Imagick object is created with the specified measurements and color as parameters. The image format is also set. Then, an image is taken as input by creating a new Imagick object. Now, the image is scaled to some specific dimension using the ‘scaleImage()’ function. The scaled image is continuously tiled on the new image that is created in the beginning using the ‘textureImage()’ function. The final output is obtained in the form ‘textureImage.png’. <?php $img=new Imagick(); $img->newImage(940, 670, new ImagickPixel(”red”)); $img->setImageFormat(“jpg”); $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.jpeg”); $image->scaleimage($image->getimagewidth() / 8, $image->getimageheight() / 8); $img=$img->textureImage($image); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/textureImage.png”); ?> Assume that the following is the input image (image.jpeg) in the program − Output Print Page Previous Next Advertisements ”;
Modifying Colors
PHP ImageMagick – Modifying Colors ”; Previous Next In this chapter, you will be learning to modify and replace different colors in an image using a few inbuilt functions provided by Imagemagick. With Imagemagick, you can adjust brightness, contrast, hue, saturation and other color parameters. You can even create complex effects such as merging multiple layers or adding special filters to your photos. This tutorial will provide an overview of how PHP Imagemagick works and how it can be used to modify the colors in digital images quickly and easily. Colorize Image Imagemagick”s ”colorizeImage()” function is an efficient way to change the color of any part of an image. This function works by blending the chosen fill color with each pixel in the picture, creating a seamless transition between colors and producing professional-looking results. The process eliminates much of the manual labor associated with changing colors on an image, such as selecting specific areas or hand-painting sections. Additionally, it saves time since it allows users to make these changes quickly and easily without sacrificing quality. Syntax public Imagick::colorizeImage(mixed $colorize, mixed $opacity, bool $legacy = false): bool This function takes 2 parameters − colorize and opacity. Colorize is an Imagick object or a string containing the colorize color, opacity is an Imagick object or a float value containing the opacity value. If opacity is 1.0, it is fully opaque and 0.0 means fully transparent. Example In this example, you will be able to clearly understand the use of ‘colorizeImage()’. An imagick object is created first and the input image is taken. Then, ‘colorizeImage()’ function is applied taking the required parameters (colorize=red and opacity=1). The image after blending colors is displayed an output using ‘writeImage()’ function. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.png”); $image->colorizeImage(”red”, 1, true); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/colorizeImage.png”); ?< Assume that the following is the input image (image.png) in the program − Output Creating a Blue Shift Image When there is a need to represent the images in moonlight or during night time you can do so using the method ‘blueShiftImage()’. This method takes an image as a parameter and mutes the colors of the image to simulate the scene nighttime in the moonlight and produces the output image. It may also involve adjusting brightness levels, saturation, contrast, and other features to ensure the end result is as close as possible to what one might expect when viewing these images in natural light conditions. Additionally, this technique can be used for creative purposes; by manipulating color values, interesting effects can be achieved with photos taken during twilight hours or even indoors with artificial lighting. Syntax public Imagick::blueShiftImage(float $factor = 1.5): bool This function takes a factor value as its parameter. It specifies the value to mute the colors of the image. Example This example shows the implementation of ‘blueShiftImage()’ function. A new imagick object is created and image is taken as input. Now, ‘blueShiftImage()’ function is applied with factor as its parameter and the output image obtained is in the form ‘blueShiftImage.png’. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.png”); $image->blueShiftImage(2); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/blueShiftImage.png”); ?> Assume that the following is the input image (image.png) in the program &Minus; Output Replacing Colors in Images In this section, you will be learning to replace colors in an image. There is an inbuilt function called ‘clutImage()’ in Imagemagick to perform this task. With the help of this function, all the colors in an image are replaced by the specific color that the user needs. This function takes an image as input and produces the image after replacing the colors as its output. ”clutImage()” function is versatile and can be used to achieve a variety of different effects. For example, you could use it to create a monochromatic image by replacing all colors in the original image with one single color. You could also use it to add vibrancy and contrast to an existing photo by swapping out duller tones for brighter ones. Syntax public Imagick::clutImage(Imagick $lookup_table, int $channel =Imagick::CHANNEL_DEFAULT): bool This function takes in 2 parameters. lookup_table which is an Imagick object containing the color lookup table channel which is a Channeltype constant. Example In the following example, an bImagick object is created with an image as its input. A second Imagick object is then created and a new image is generated which selects ”violet” from the lookup table. The `clutImage()` method is used to replace colors, where ”violet” has been specified and no ChannelType constant has been declared; thus, the default channel will be utilized. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/imagee.png”); $clut = new Imagick(); $clut->newImage(1, 1, new ImagickPixel(”violet”)); $image->clutImage($clut); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/clutImage.png”); ?> Assume that the following is the input image (image.png) in the program − Output Negation of Images Negating the colors in images implies the reversing or inverting of the colors. For example, assume an image containing white and black colors. After negating the colors, white changes to black and black changes to white. The ”negateImage()” function is used to negate/inverse the colors in PHP ImageMagick, You might also use this effect to create high-contrast images by changing light tones into dark ones or deep hues into bright ones. Additionally, it is possible to achieve more subtle color shifts in your images by applying partial color negation; this means that only certain parts of the image are affected while others remain untouched. Syntax public Imagick::negateImage(bool $gray, int $channel =Imagick::CHANNEL_DEFAULT): bool This function takes in 2 parameters: gray and channel. Gray is a boolean value that decides whether to negate grayscale pixels within the image. Channel provides any channel constant that is valid for your channel mode.
Different effects
PHP ImageMagick – Different effects ”; Previous Next Creating a 3D Effect A picture that appears to be having height, width, and depth is called a 3-dimensional(3D) picture. 3D images provide a realistic replica of the object to the users. To create this effect directly on the server, Imagemagick offers an inbuilt function called ”shadeImage()”. This is handy and it is capable of transforming standard 2D images into high-quality 3D renderings with ease. Syntax public Imagick::shadeImage(bool $gray, float $azimuth, float $elevation): bool This function takes 3 parameters: gray, azimuth, and elevation. Gray is a Boolean value that is used to shade the intensity of each pixel. Azimuth’ and ‘elevation’ are float values that define the light source directions off the x-axis and above the z-axis respectively. For creating a 3D effect, the amount of light and the direction of light is mainly considered. This function the image as input and produces the image with a 3D effect as output. Example This example shows the use of the ”shadeImage()” function In here, an Imagick object is created and an image is passed as input. The ”shadeImage()” function is then called with gray value, azimuth value, and elevation supplied as parameters. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.png”); $image->shadeImage(true, 50, 30); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/shadeImage.png”); ?> Assume that the following is the input image (image.png) in the program − Output Creating a Solarizing Effect The effect that is seen when the photographic film is extremely overexposed is called as the solarize effect. To create that effect in PHP, there is an inbuilt function ‘solarizeImage()’ provided by Imagemagick. This effect results in an image with reversed tones, where the highlights become dark and vice versa. Syntax public Imagick::solarizeImage(int $threshold): bool This function takes ‘threshold’ as a parameter. It is an integer value that is used to measure the extent of the solarizing effect. Example This example shows the implementation of ‘solarizeImage()’ function. A new imagick object is created and image is taken as input. Now, ‘solarizeImage()’ function is applied with a threshold value as its parameter and the output image obtained is in the form ‘solarizeImage.png’. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/imagee.png”); $image->solarizeImage(0.3); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/solarizeImage.png”); ?> Assume that the following is the input image (image.png) in the program − Output Creating a Wave Filter Effect Imagemagick has provided an inbuilt function called ‘waveImage()’ which helps in simulating a wave filter on an image. It takes an image as input and the output obtained is the image with a wave filter. Syntax public Imagick::waveImage(float $amplitude, float $length): bool This function has two parameters: amplitude and length. Amplitude specifies the amplitude of the wave. length specifies the length of the wave. Example This is an example which shows the implementation of ‘waveImage()’ function. At first, a new imagick object is created and an image is taken as input. Then, ‘waveImage()’ function is applied on that image. The required output is obtained in the form of ‘waveImage.png’. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.png”); $image->waveImage(2, 4); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/waveImage.png”); ?> Assume that the following is the input image (image.png) in the program − Output Creating a Swirl Effect In this chapter, you will be learning to swirl an image. Generally, swirling means to move quickly with a twisting or a circular movement. The image that contains this type of effect is called a swirled image. Creating a swirl image manually is difficult. But, to make this easier, Imagemagick has provided an inbuilt function ‘swirlImage()’ which swirls the pixels about the center of the image. Syntax Imagick::swirlImage(float $degrees): bool This function takes in a single parameter: degrees. ‘Degrees’ is a float value that indicates the sweep of the arc through which each pixel is moved. By this, you get a more dramatic effect as the degrees move from 1 to 360. Example In the below example, you first create a new imagick object and input an image. Then, ‘swirlImage()’ function is applied by specifying the degrees(degrees=200). And finally, that swirled image is obtained as output. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/imagee.png”); $image->swirlImage(200); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/swirlImage.png”); ?> Assume that the following is the input image (image.png) in the program − Output Print Page Previous Next Advertisements ”;
Image Reflections
PHP ImageMagick – Image Reflections ”; Previous Next Image reflections are a type of image manipulation technique used to create mirror images or symmetrical patterns. This effect is achieved by copying and flipping an image horizontally or vertically, creating a mirrored version of the original. In this chapter we will explore how to use the PHP Imagemagick library to create image reflections with ease. We”ll cover basic concepts such as reflection types, size adjustments, and color manipulations to give you a comprehensive understanding of the process and help you create beautiful reflective effects quickly and easily. Image Flipping Flipping an image is the process of making a reflected duplication of that image vertically. So, for flipping an image, we have a method ‘flipImage()’ in Imagemagick. This function helps to display the vertical mirror image of the input. Syntax bool Imagick::flipImage(void) This function does not accept any parameters. Example In this example, you”ll learn how to use the ”flipImage()” function in PHP. To get started, create a new Imagick object and read the input image. Then, use the flipImage() method to flip it vertically. You can either display the flipped image directly on the server or save it to your system using writeImage(). <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.jpg”); $image->flipImage(); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/flipImage.png”); ?> Assume that the following is the input image (image.jpg) in the program − Output Image Flopping Flopping an image is the process of making a reflected duplication of that image horizontally. So, for flopping an image, we have a method ‘flopImage()’ in Imagemagick. This function helps to display the horizontal mirror image of the input. Syntax bool Imagick::flopImage(void) This function does not accept any parameters. Example In this example, you”ll learn how flop an image using the ”flopImage()” function in PHP. To start, create a new Imagick object and read the input image. Next, use the ”flopImage()” function to flip it horizontally. The flipped image will return as output. <?php $image=new Imagick($_SERVER[”DOCUMENT_ROOT”].”/test/image.jpg”); $image->flopImage(); $image->writeImage($_SERVER[”DOCUMENT_ROOT”].”/test/flopImage.png”); ?> Assume that the following is the input image (image.jpg) in the program − Output Print Page Previous Next Advertisements ”;
PHP ImageMagick – Discussion
Discuss – PHP ImageMagick ”; Previous Next Imagick is a PHP extension that allows us to use the ImageMagick API to create and edit images. ImageMagick is a bitmap image creation, editing, and composition software suite. DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF are among the formats it can read, convert, and write. It is used for file format conversion, color quantization, liquid rescaling, dithering, and many artistic effects.. Print Page Previous Next Advertisements ”;