Metinfo 5.0 image watermark bug modification and added support for transparent background png watermark

Source: Internet
Author: User

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.





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.