Write a php program to scale a given image
View Discussion Show Improve Article Save Article View Discussion Improve Article Save Article The imagescale() function is an inbuilt function in PHP which is used to scale an image using the given new width and height. Syntax: resource imagescale( $image, $new_width, $new_height = -1, $mode = IMG_BILINEAR_FIXED ) Parameters: This function accepts four parameters as mentioned above and described below:
Return Value: This function return the resource of scaled image on success or False on failure. Below programs illustrate the imagescale() function in PHP: Program 1: Output: Program 2:
Output: Reference: https://www.php.net/manual/en/function.imagescale.php ImageCopyResized(dest, src, dx, dy, sx, sy, dw, dh, sw, sh); ImageCopyResampled(dest, src, dx, dy, sx, sy, dw, dh, sw, sh); The dest and src parameters are image handles. The point (dx,dy) is the point in the destination image where the region will be copied. The point (sx,sy) is the upper-left corner of the source image. The sw, sh, dw, and dh parameters give the width and height of the copy regions in the source and destination. Example 9-10 takes the php.jpg image shown in Figure 9-8 and smoothly scales it down to one-quarter of its size, yielding the image in Figure 9-9. (PHP 5 >= 5.5.0, PHP 7, PHP 8) imagescale — Scale an image using the given new width and height Descriptionimagescale(
Parametersimage A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor(). width The width to scale the image to. height The height to scale the image to. If omitted or negative, the aspect ratio will be preserved. mode One of
Return Values Return the scaled image object on success or Changelog
See Also
How do I scale an image in PHP?The imagescale() function is an inbuilt function in PHP which is used to scale an image using the given new width and height. Parameters: This function accepts four parameters as mentioned above and described below: $image: It is returned by one of the image creation functions, such as imagecreatetruecolor().
How to resize image in PHP with example?Images can be resized using ImageMagick or GD functions. If GD's functions are used, the size of the image file is also reduced when raw digital camera images are sampled.
How can we get the properties of an image size type width height using PHP image functions?imagesx() and imagesy() The imagesx() and imagesy() are used to extract the width and height of the images respectively. For that, it accepts the resource type of data which will be returned on creating new images dynamically using PHP script.
|