Home  >  Article  >  Backend Development  >  PHP code to upload images and add transparent watermarks

PHP code to upload images and add transparent watermarks

WBOY
WBOYOriginal
2016-07-25 09:03:471208browse
  1. $im = imagecreatefromjpeg($_file["upload"]["tmp_name"]); //You want to draw a picture of the water example
  2. $watermark = imagecreatefrompng("Smiley.png") ; //The path of the watermark image
  3. $im_x = imagesx($im);
  4. $im_y = imagesy($im);
  5. $w_x = imagesx($watermark);
  6. $w_y = imagesy($watermark);
  7. imagecopy( $im,$watermark ,$im_x-$w_x,$im_y-$w_y,0,0,$w_x,$w_y);
  8. imagejpeg($im); //You can add a path to save the image with watermark
  9. / /You can use type to determine the image type
  10. //switch($_file["upload"]["type"])
  11. //case:1
  12. //Then use different functions
  13. //imagejpeg() to correspond to jpeg
  14. / /imagegif() corresponds to gif
  15. //imagepng() corresponds to png
  16. imagedestroy($im);
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