$watermark=1; //Whether to attach a watermark (1 is watermarked, others are not watermarked);
$watertype=1; //Watermark type (1 is text, 2 is picture)
$waterposition=1; //Watermark position (1 is the lower left corner, 2 is Lower right corner, 3 is the upper left corner, 4 is the upper right corner, 5 is the center);
$waterstring="JYS studio"; //Watermark string
$waterimg="xplore.gif";//Watermark image
$imgpreview= 1; //Whether to generate a preview image (1 means generate, others do not generate);
$imgpreviewsize=1/2; //Thumbnail ratio
?>
Upload file:
The file types allowed to be uploaded are: =implode(', ',$uptypes)?>
< ;/form>
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
//Does the file exist?
if (!is_uploaded_file($_FILES["upfile"][tmp_name]) )
{
echo "The picture does not exist!";
exit;
}
$file = $_FILES["upfile"];
//Check the file size
if($max_file_size < ; $file["size"])
{
echo "The file is too big! Cannot exceed 2M! ";
exit;
}
//Check the file type
if(!in_array($file["type"], $uptypes))
{
echo "The file type does not match!" .$file["type"];
exit;
}
//If the uploaded folder does not exist, it will be automatically created
if(!file_exists($destination_folder))
{
mkdir ($destination_folder);
}
$filename=$file["tmp_name"]; //The temporary file name automatically generated by the system
$filenamecustom = $file["name"]; / /The file name uploaded by the user
$pinfo=pathinfo($file["name"]); //The path information of the uploaded file
$ftype=$pinfo[' extension']; //The extension of the uploaded file
//$destination = $destination_folder.time().".".$ftype;//The directory + file name + file type of the uploaded file, the file name is determined by time() Generate
$destination = $destination_folder.$filenamecustom.".".$ftype;//Directory of uploaded file + user file name + file type
//Check whether the file with the same name exists
if (file_exists($destination) && $overwrite != true)
{
echo "The file with the same name already exists";
$iinfo=getimagesize($destination,$iinfo); //Get the image size and type
$nimage=imagecreatetruecolor($image_size[0],$image_size[1]); //Create a true color image and return an image identifier Symbol,
//Represents a black image of size x_size and y_size
$white=imagecolorallocate($nimage,255,255,255); //nimage assigns color
$black=imagecolorallocate($nimage,0,0,0). ;
$red=imagecolorallocate($nimage,255,0,0);
imagefill($nimage,0,0,$white); //The coordinates x, y of the nimage image (the upper left corner of the image is 0, 0) Use color color to perform area filling
// (that is, points with the same color as the x, y point and adjacent points will be filled)
$simage =imagecreatefromgif($destination); //The image obtained from the given file name
break;
case 2:
$simage =imagecreatefromjpeg($destination);
break;
case 3:
$simage =imagecreatefrompng($destination);
break;
case 6:
$simage =imagecreatefromwbmp($destination);
break;
default:
die("Unsupported file type"); //Equivalent to exit()
exit;
}
imagecopy($nimage,$simage,0,0,0,0,$image_size[0], $image_size[1]);//Copy simage starting from 0,0, $image_size[0] width, $image_size[1] height
//Copy a part of simage to the position with coordinates 0,0 in nimage p>
imagefilledrectangle($nimage,1,$image_size[1]-15,80,$image_size[1],$white);//Draw an upper left corner coordinate of 1 in the nimage image with white color , $image_size[1]-15
//Rectangle with lower right corner coordinates 80, $image_size[1]
switch($watertype)
{
case 1: //Add watermark string
imagestring($nimage,2, 3,$image_size[1]-15,$waterstring,$black);//Draw the waterstring in black to the 3,$image_size[1]-15 coordinates of nimage, and the font is the built-in font 2
break;
case 2 : //Add watermark image
$simage1 =imagecreatefromgif("xplore.gif");
imagecopy($nimage,$simage1,0,0,0,0,85,15);
imagedestroy($simage1); // Release the memory associated with simagel
break;
}
switch ($iinfo[2])
{
case 1:
//imagegif($nimage, $destination);
imagejpeg($nimage, $destination); // Creates a JPEG image with destination as the file name from the nimage image. The nimage parameter is the return value of the imagecreatetruecolor() function.
break;
case 2:
imagejpeg($nimage, $destination);
break;
case 3:
imagepng($nimage, $destination) );
break;
case 6:
imagewbmp($nimage, $destination);
//imagejpeg($nimage, $destination);
break;
}
//Release memory
imagedestroy($nimage);
imagedestroy($simage);
}
if($imgpreview==1)
{
echo " Image preview: ";
echo "";
}
}
?>
Copy code
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn