Php to generate a rounded corner image, _ PHP Tutorial

Source: Internet
Author: User
Php generates a rounded image ,. Php generates a rounded image. This article describes how php generates a rounded image. Share it with you for your reference. The specific code is as follows: how php $ image_file php generates a rounded image,

This example describes how to generate a rounded corner image using php. Share it with you for your reference. The details are as follows:
The code is as follows: <? Php
$ Image_file = $ _ GET ['src'];
$ Corner_radius = isset ($ _ GET ['radius '])? $ _ GET ['radius ']: 20; // The default corner radius is set to 20px
$ Topleft = (isset ($ _ GET ['topleft']) and $ _ GET ['topleft'] = "no ")? False: true; // Top-left rounded corner is shown by default
$ Bottomleft = (isset ($ _ GET ['bottomleft']) and $ _ GET ['bottomleft'] = "no ")? False: true; // Bottom-left rounded corner is shown by default
$ Bottomright = (isset ($ _ GET ['bottomright']) and $ _ GET ['bottomright'] = "no ")? False: true; // Bottom-right rounded corner is shown by default
$ Topright = (isset ($ _ GET ['topright']) and $ _ GET ['topright'] = "no ")? False: true; // Top-right rounded corner is shown by default
$ Imagetype = strtolower ($ _ GET ['imagetype ']);
$ Backcolor = $ _ GET ['backcolor'];
$ Endsize = $ corner_radius;
$ Startsize = $ endsize * 3-1;
$ Arcsize = $ startsize * 2 + 1;
If ($ imagetype = 'jpeg ') or ($ imagetype = 'jpg ')){
$ Image = imagecreatefromjpeg ($ image_file );
} Else {
If ($ imagetype = 'GIF') or ($ imagetype = 'GIF ')){
$ Image = imagecreatefromgif ($ image_file );
} Else {
$ Image = imagecreatefrompng ($ image_file );
}
}
$ Size = getimagesize ($ image_file );
// Top-left corner
$ Background = imagecreatetruecolor ($ size [0], $ size [1]);
Imagecopymerge ($ background, $ image, 100, $ size [0], $ size [1 );
$ Startx = $ size [0] * 2-1;
$ Starty = $ size [1] * 2-1;
$ Im_temp = imagecreatetruecolor ($ startx, $ starty );
Imagecopyresampled ($ im_temp, $ background, 0, 0, 0, 0, $ startx, $ starty, $ size [0], $ size [1]);
$ Bg = imagecolorallocate ($ im_temp, hexdec (substr ($ backcolor,), hexdec (substr ($ backcolor,), hexdec (substr ($ backcolor, 4, 2 )));
$ Fg = imagecolorallocate ($ im_temp, hexdec (substr ($ forecolor,), hexdec (substr ($ forecolor,), hexdec (substr ($ forecolor, 4, 2 )));
If ($ topleft = true ){
Imagearc ($ im_temp, $ startsize, $ startsize, $ arcsize, $ arcsize, 180,270, $ bg );
Imagefilltoborder ($ im_temp, 0, 0, $ bg, $ bg );
}
// Bottom-left corner
If ($ bottomleft = true ){
Imagearc ($ im_temp, $ startsize, $ starty-$ startsize, $ arcsize, $ arcsize, 90,180, $ bg );
Imagefilltoborder ($ im_temp, 0, $ starty, $ bg, $ bg );
}
// Bottom-right corner
If ($ bottomright = true ){
Imagearc ($ im_temp, $ startx-$ startsize, $ starty-$ startsize, $ arcsize, $ arcsize, 0, 90, $ bg );
Imagefilltoborder ($ im_temp, $ startx, $ starty, $ bg, $ bg );
}
// Top-right corner
If ($ topright = true ){
Imagearc ($ im_temp, $ startx-$ startsize, $ startsize, $ arcsize, $ arcsize, 270,360, $ bg );
Imagefilltoborder ($ im_temp, $ startx, 0, $ bg, $ bg );
}
$ Newimage = imagecreatetruecolor ($ size [0], $ size [1]);
Imagecopyresampled ($ image, $ im_temp, 0, 0, 0, $ size [0], $ size [1], $ startx, $ starty );
// Output final image
Header ("Content-type: image/png ");
Imagepng ($ image );
Imagedestroy ($ image );
Imagedestroy ($ background );
Imagedestroy ($ im_temp );
?>

I hope this article will help you with php programming.

Examples in this article describes how php generates a rounded corner image. Share it with you for your reference. The code is as follows: php $ image_file =...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.