PHP Picture Processing Notes

Source: Internet
Author: User
Tags transparent color

<?php

/*
Based on STR generation
Header ("Content-type:image/png");
$IMAGEURL = "Http://www.ci123.com/index/styles/images/index_fwq.png";
$str =file_get_contents ($IMAGEURL);
$a =imagecreatefromstring ($STR);
Imagepng ($a);//have filename for generation, inaction display
Imagedestroy ();
*/

/*
Create a picture with a background perfect operation ~ non-transparent
Header ("Content-type:image/png");
$IMAGEURL = "Http://www.ci123.com/index/styles/images/index_fwq.png";
$s 1=imagecreatefrompng ($IMAGEURL);
$w =imagesx ($s 1);
$h =imagesy ($s 1);
$d 1=imagecreatetruecolor ($w, $h);

$white = imagecolorallocate ($d 1, 255, 255, 255);//Create a white background generate call the first call to Imagecolorallocate () fills the background color of the palette-based image with the IMAGEC The image created by reate ().
Imagefilledrectangle ($d 1, 0, 0, $w, $h, $white);//Draw a uniform size rectangle to act as a background
imagecopyresampled ($d 1, $s 1,0,0,0,0, $w, $h, $w, $ h);
Imagepng ($d 1);//have filename for generation, inactivity display
Imagedestroy ($d 1);//
*/


/*
Generate PNG pictures
Header ("Content-type:image/png");
$IMAGEURL = "./4.png";
$s 1=imagecreatefrompng ($IMAGEURL);
$w =imagesx ($s 1);
$h =imagesy ($s 1);
$d 1=imagecreatetruecolor ($w, $h);
$white = Imagecolorallocate ($d 1, 255, 255, 255);//create transparent white background 0-127 0 for completely opaque
Imagefilledrectangle ($d 1, 0, 0, $w, $h, $white); Draw a uniform size rectangle to act as a background
Imagecolortransparent ($d 1, $white);//imagecolortransparent () sets the transparent color in image images to color. The image is the Imagecreatetruecolor () return identifier of the color, which is the colour identifier returned by Imagecolorallocate (). Note: Transparent color is an attribute of an image, and transparency is not a property of a color. Once you have set a color as a transparent color, any areas of the image that were previously drawn as that color become transparent. Transparency can only be copied through Imagecopymerge () and true color images, not imagecopy () or palette images.
Imagecolorallocatealpha ($d 1,255,255,255,127);
Imagecopyresampled ($d 1, $s 1,0,0,0,0, $w, $h, $w, $h);
Imagepng ($d 1);//have filename for generation, inaction display
Imagedestroy ($d 1);
The combination of imagecolorallocate+imagecolortransparent creates a transparent background

*/

/*header ("Content-type:image/png");
$IMAGEURL = "Http://www.ci123.com/index/styles/images/index_fwq.png";
$s 1=imagecreatefrompng ($IMAGEURL);
$w =imagesx ($s 1);
$h =imagesy ($s 1);
$d 1=imagecreate ($w, $h);
$white = Imagecolorallocate ($d 1, 255, 255, 255); Creating a white background call to the first call to Imagecolorallocate () fills the color palette-based image with the background color, which is the image created with Imagecreate ().
Imagecopyresampled ($d 1, $s 1,0,0,0,0, $w, $h, $w, $h);
Imagepng ($d 1);//have filename for generation, inaction display
Imagedestroy ($d 1);
*/
/*
Header ("Content-type:image/png");
$IMAGEURL = "Http://www.ci123.com/index/styles/images/index_fwq.png";
$s 1=imagecreatepng ($IMAGEURL);
$w =imagesx ($s 1);
$h =imagesy ($s 1);
$d 1=imagecreatetruecolor ($w, $h);
$bgcolor = Imagecolorallocatealpha ($d 1, 255, 255, 255, 127); Create a transparent white background
Imagefilledrectangle ($d 1, 0, 0, $w, $h, $bgcolor); Draw a uniform size rectangle to act as a background

Imagecopyresampled ($d 1, $s 1,0,0,0,0, $w, $h, $w, $h);
Imagepng ($d 1, "1.png");//have filename for generation, inaction display
Imagedestroy ();
*/


/*
Direct Imagepng generated PNG will be damaged
Imagepng ($a, Time (). ". PNG ", 0);
Imagecreatefromstring accepts IMAGETSR non-Base64 encoding.

The imagecreatetruecolor (int x,int y) is a black image of size x and Y (black by default), which requires a fill color function Imagefill ($img, 0,0, $color) If you want to change the background color;
Imagecreate Create a new blank image resource, add a background color with imagecolorallocate () http://blog.sina.com.cn/s/blog_68b56adb0100vnhn.html

Allocate invalid for generating PNG picture

*/

function selimg ($s 1, $s 2) {
Header ("Content-type:image/png");
$aw = 600;
$ah = 400;
$s 1=imagecreatefromjpeg ($s 1);
$s 2=imagecreatefromjpeg ($s 2);
$aim =imagecreatetruecolor ($aw, $ah);
$width =imagecolorallocate ($aim, 255,255,255);
Imagecopyresampled ($aim, $s 1,0,0,0,0, $aw/2, $ah, Imagesx ($s 1), imagesy ($s 1));
Imagecopyresampled ($aim, $s 2, $aw/2,0,0,0, $aw/2, $ah, Imagesx ($s 2), imagesy ($s 2));
Imagejpeg ($aim, "", 100);
Imagedestroy ($aim);
}
$s 1= "http://shiyong.ci123.com/images/upload/20170414164129_big.jpg";
$s 2= "http://shiyong.ci123.com/images/upload/20171009095428_big.jpg";
Selimg ($s 1, $s 2);
?>

PHP Picture Processing Notes

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.