Recently, I used metinfo 5.0 to build my own small site. The feature is quite good and useful. I found many small problems and I have done almost the same thing. I am too lazy to switch to other cms, fix it by yourself ~
Problem 1: The image watermark function is enabled on the website background, but the system does not save the watermark image for the uploaded image in jpeg format, the watermark image of this image is not available in the system upload/watermark/directory. This problem is not found when the uploaded image is in png, jpg, or gif format.
Debugging program source code discovery: admin/include/watermark. class. php file 102nd:
function createImage($type,$img_name){ if (!$type){ $type = $this->get_type($img_name); } switch ($type){ case 'gif': if (function_exists('imagecreatefromgif')) $tmp_img=@imagecreatefromgif($img_name); break; case 'jpg': $tmp_img=imagecreatefromjpeg($img_name); break; case 'png': $tmp_img=imagecreatefrompng($img_name); break; default: $tmp_img=imagecreatefromstring($img_name); break; } return $tmp_img;}
The jpeg format is not determined. Therefore, the following statements are added to the switch:
case 'jpeg': $tmp_img=imagecreatefromjpeg($img_name); break;
Solve the problem.
Question 2: If you want to add watermarks to all images on the website, use the png Website logo with your own transparent background as the watermark image, set the background, and upload an image for testing,
I found that the transparent background color of the png image was completely messy. I went to the official website to search for related problems. I found that it was not supported yet, so I changed it myself.
The procedure is as follows:
1. admin/include/watermark. class. php: Add a function that supports png watermarks with transparent backgrounds (found online)
function imagecopymerge_alpha($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct){$opacity=$pct;// getting the watermark width$w = imagesx($src_im);// getting the watermark height$h = imagesy($src_im); // creating a cut resource$cut = imagecreatetruecolor($src_w, $src_h);// copying that section of the background to the cutimagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h);// inverting the opacity$opacity = $opacity;//100 - $opacity; // placing the watermark nowimagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h);imagecopymerge($dst_im, $cut, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $opacity);}
2. admin/include/watermark. class. php row 53rd
Set
imagecopymerge($src_image,$met_image,$met_image_x,$met_image_y,0,0,$met_image_w,$met_image_h,$this->met_image_transition);
Replace
if(strpos($this->met_image_name,'.png')!==false){ $this->imagecopymerge_alpha($src_image,$met_image,$met_image_x,$met_image_y,0,0,$met_image_w,$met_image_h,$this->met_image_transition); }else{ imagecopymerge($src_image,$met_image,$met_image_x,$met_image_y,0,0,$met_image_w,$met_image_h,$this->met_image_transition); }
That is, if it is a png watermark with a transparent background, call the newly added function.
The test is successful.