<无详细内容>
-
- /* PHP image and text watermark class library
-
- Currently, this class library only supports text watermarks. the position is in the lower right corner and the color is random.
-
- Call method:
- 1. introduce a class library at the top of the file to be watermarked:
- Include_once 'imageclass. php ';
- 2. declare a new class:
- $ Tpl = new image_fu;
- 3. provide parameters for image watermarks:
- $ Tpl-> img (image path, watermark text, font path, font size, font angle );
- For example: $ tpl-> img('abc.jpg ', 'This is the watermark text', 'ziti. ttf)
-
- */
- Class image_fu {
-
- Private $ image;
- Private $ img_info;
- Private $ img_width;
- Private $ img_height;
- Private $ img_im;
- Private $ img_text;
- Private $ img_ttf = '';
- Private $ img_new;
- Private $ img_text_size;
- Private $ img_jd;
-
-
- Function img ($ img = '', $ txt ='', $ ttf = '', $ size = 12, $ jiaodu = 0 ){
- If (isset ($ img) & file_exists ($ img) {// check whether the image exists
- $ This-> image = $ img;
- $ This-> img_text = $ txt;
- $ This-> img_text_size = $ size;
- $ This-> img_jd = $ jiaodu;
- If (file_exists ($ ttf )){
- $ This-> img_ttf = $ ttf;
- } Else {
- Exit ('font File: '. $ ttf.' does not exist! ');
- }
- $ This-> imgyesno ();
- } Else {
- Exit ('Image File: '. $ img.' doesn't exist ');
- }
- }
-
- Private function imgyesno (){
-
- $ This-> img_info = getimagesize ($ this-> image );
- $ This-> img_width = $ this-> img_info [0]; // image width
- $ This-> img_height = $ this-> img_info [1]; // picture height
-
- // Check the image type
- Switch ($ this-> img_info [2]) {
- Case 1: $ this-> img_im = imagecreatefromgif ($ this-> image); break;
- Case 2: $ this-> img_im = imagecreatefromjpeg ($ this-> image); break;
- Case 3: $ this-> img_im = imagecreatefrompng ($ this-> image); break;
- Default: exit ('watermarks are not supported in image format ');
- }
-
- $ This-> img_text ();
- }
-
-
- Private function img_text (){
-
- Imagealphablending ($ this-> img_im, true );
-
- // Set the color
- $ Color = imagecolorallocate ($ this-> img_im, 255,255,255 );
- $ Txt_height = $ this-> img_text_size;
- $ Txt_jiaodu = $ this-> img_jd;
- $ Ttf_im = imagettfbbox ($ txt_height, $ txt_jiaodu, $ this-> img_ttf, $ this-> img_text );
- $ W = $ ttf_im [2]-$ ttf_im [6];
- $ H = $ ttf_im [3]-$ ttf_im [7];
- // $ W = $ ttf_im [7];
- // $ H = $ ttf_im [8];
- Unset ($ ttf_im );
-
- $ Txt_y = $ this-> img_height * 0.5;
- $ Txt_x = $ this-> img_width * 0.2;
- // $ Txt_y = 0;
- // $ Txt_x = 0;
-
-
- $ This-> img_new = @ imagettftext ($ this-> img_im, $ txt_height, $ txt_jiaodu, $ txt_x, $ txt_y, $ color, $ this-> img_ttf, $ this-> img_text );
-
- @ Unlink ($ this-> image); // delete an image
- Switch ($ this-> img_info [2]) {// Obtain the background image format
- Case 1: imagegif ($ this-> img_im, $ this-> image); break;
- Case 2: imagejpeg ($ this-> img_im, $ this-> image); break;
- Case 3: imagepng ($ this-> img_im, $ this-> image); break;
- Default: exit ('watermark Image failed ');
- }
- }
-
-
- // Display the image
- Function img_show () {echo 'image. '"border =" 0 "alt ="'. $ this-> img_text. '"/> ';}
-
- // Release the memory
- Private function img_nothing (){
- Unset ($ this-> img_info );
- Imagedestroy ($ this-> img_im );
- }
-
- }
-
- ?>
- /**
- * Created by JetBrains PhpStorm.
- * User: taoqili
- * Date: 12-7-18
- * Time: AM
- */
- Header ("Content-Type: text/html; charset = utf-8 ");
- Error_reporting (E_ERROR | E_WARNING );
- Include "Uploader. class. php ";
- // Upload the description form name in the image box,
- $ Title = htmlspecialchars ($ _ POST ['pictitle'], ENT_QUOTES );
- $ Path = htmlspecialchars ($ _ POST ['dir'], ENT_QUOTES );
- // Upload configuration
- $ Config = array (
- "SavePath" => ($ path = "1 "? "Upload/": "upload1 /"),
- "MaxSize" => 1000, // unit: KB
- "AllowFiles" => array (". gif", ". png", ". jpg", ". jpeg", ". bmp ")
- );
- // Generate and upload the instance object
- $ Up = new Uploader ("upfile", $ config );
- /**
- * Obtain the parameters and array structure corresponding to the uploaded file.
- * Array (
- * "OriginalName" => "", // original file name
- * "Name" => "", // new file name
- * "Url" => "", // return address
- * "Size" => "", // file size
- * "Type" => "", // file type
- * "State" => "" // Upload status. if the upload is successful, "SUCCESS" must be returned"
- *)
- */
- $ Info = $ up-> getFileInfo ();
- /**
- * Return json data to the browser
- *{
- * 'URL': 'a.jpg ', // path of the saved file
- * 'Title': 'hello', // file description, which is added to the title attribute on the front end of the image.
- * 'Original': 'B .jpg', // original file name
- * 'State': 'success' // Upload status. if the upload succeeds, SUCCESS is returned. other values are returned to the image upload box as they are.
- *}
- */
- /* Include "imgwater. php ";
- $ Tpl = new image_fu;
- $ Tpl-> img ($ info ['URL'], 'http: // www.zgxbzh.com/', 'simsun.ttc', 30,0 );*/
- Echo "{'URL ':'". $ info ["url"]. "', 'Title ':'". $ title. "', 'original ':'". $ info ["originalName"]. "', 'State ':'". $ info ["state"]. "'}";
|