Warum kann ich kein Wasserzeichen hinzufügen und das Bild kann nicht ausgegeben werden? Es gibt nur ein kleines Kästchen. Das Gleiche gilt für die vorherige Bildskalierung und den Zuschnitt.
城南花已开
城南花已开 2018-12-11 15:16:07
0
1
1741
<?php
// 获取图片宽度、高度和类型
$img='abc.jpeg';
print_r(getImageInfo($img));
echo '<br/>';
function getImageInfo($img){
  $info= getimagesize($img);
  $imageinfo=pathinfo($img);
  $getImageInfo=array(
    'width' =>$info[0],
    'height'=>$info[1],
     'type'=>$imageinfo['extension'],
    );
    return $getImageInfo;
}
water('abc.jpeg','du.png');
function water($img,$water,$pos=9,$tm=100){
   $info=getImageInfo($img);
   $logo=getImageInfo($water);
   $dst=openImg($img,$info['type']);
   $src=openImg($water,$logo['type']);
   switch($pos){
       case 1:
           $x=0;
           $y=0;
           break;
       case 2:
           $x=ceil(($info['width']-$logo['width'])/2);
           $y=0;
           break;
       case 3:
           $x=$info['width']-$logo['width'];
           $y=0;
           break;
       case 4:
           $x=0;
           $y=ceil(($info['height']-$logo['height'])/2);
           break;
       case 5:
           $x=ceil(($info['width']-$logo['width'])/2);
           $y=ceil(($info['height']-$logo['height'])/2);
           break;
       case 6:
           $x=$info['width']-$logo['width'];
           $y=ceil(($info['height']-$logo['height'])/2);
           break;
       case 7:
           $x=0;
           $y=$info['height']-$logo['height'];
           break;
       case 8:
           $x=ceil(($info['width']-$logo['width'])/2);
           $y=$info['height']-$logo['height'];
           break;
       case 9:
           $x=$info['width']-$logo['width'];
           $y=$info['height']-$logo['height'];
           break;
       case 0:
       default:
           $x=mt_rand(0,$info['width']-$logo['width']);
           $y=mt_rand(0,$y=$info['height']-$logo['height']);
           break;
   }
   imagecopymerge($dst,$src,$x,$y,0,0,$logo['width'],$logo['height'],$tm);
header ('Content-Type:image/jpeg');
   imagejpeg($dst);
   imagedestory($dst);
   imagedestory($src);
}
   function openImg($path,$type){
       switch($type){
           case 'jpeg':
           case 'jpg':
           case 'pjpeg':
               $img=imagecreatefromjpeg($path);
               break;
           case 'png':
           case 'x-png':
               $img=imagecreatefrompng($path);
               break;
           case 'gif':
               $img=imagecreatefromgif($path);
               break;
           case 'wbmp':
               $img=imagecreatefromwbmp($path);
               break;
           default:
               exit('图片类型不支持');
       }
       return $img;
   }
?>


城南花已开
城南花已开

Antworte allen(1)
啊啊啊啊啊啊啊啊啊欧

如果图片直接改后缀名,会导致这种情况,可通过PS修改后缀名,希望回答有所帮助。

<?php
// 获取图片宽度、高度和类型

// $img='time.jpg';

// print_r(getImageInfo($img));

// echo '<br/>';

function getImageInfo($img){

 $info= getimagesize($img);

 $imageinfo=pathinfo($img);

 $getImageInfo=array(

   'width' =>$info[0],

   'height'=>$info[1],

    'type'=>$imageinfo['extension'],

   );

   return $getImageInfo;

}

water('photo.jpeg','watermark.png');

function water($img,$water,$pos=9,$tm=100){

  $info=getImageInfo($img);

  $logo=getImageInfo($water);

  $dst=openImg($img,$info['type']);

  $src=openImg($water,$logo['type']);

  switch($pos){

      case 1:

          $x=0;

          $y=0;

          break;

      case 2:

          $x=ceil(($info['width']-$logo['width'])/2);

          $y=0;

          break;

      case 3:

          $x=$info['width']-$logo['width'];

          $y=0;

          break;

      case 4:

          $x=0;

          $y=ceil(($info['height']-$logo['height'])/2);

          break;

      case 5:

          $x=ceil(($info['width']-$logo['width'])/2);

          $y=ceil(($info['height']-$logo['height'])/2);

          break;

      case 6:

          $x=$info['width']-$logo['width'];

          $y=ceil(($info['height']-$logo['height'])/2);

          break;

      case 7:

          $x=0;

          $y=$info['height']-$logo['height'];

          break;

      case 8:

          $x=ceil(($info['width']-$logo['width'])/2);

          $y=$info['height']-$logo['height'];

          break;

      case 9:

          $x=$info['width']-$logo['width'];

          $y=$info['height']-$logo['height'];

          break;

      case 0:

      default:

          $x=mt_rand(0,$info['width']-$logo['width']);

          $y=mt_rand(0,$y=$info['height']-$logo['height']);

          break;

  }

  imagecopymerge($dst,$src,$x,$y,0,0,$logo['width'],$logo['height'],$tm);

header ('Content-Type:image/jpeg');

  imagejpeg($dst);

  imagedestory($dst);

  imagedestory($src);

}

  function openImg($path,$type){

      switch($type){

          case 'jpeg':

          case 'jpg':

          case 'pjpeg':

              $img=imagecreatefromjpeg($path);

              break;

          case 'png':

          case 'x-png':

              $img=imagecreatefrompng($path);

              break;

          case 'gif':

              $img=imagecreatefromgif($path);

              break;

          case 'wbmp':

              $img=imagecreatefromwbmp($path);

              break;

          default:

              exit('图片类型不支持');

      }

      return $img;

  }

?>

另外课程上的方法(亲测可用),不同在于getImageInfo函数。

<?php
header("content-type:text/html;charset=utf-8");  
water('photo.jpeg','watermark.jpeg');
function getImageInfo($path) {
   $info = getimagesize($path);
   $data['width'] = $info[0];
   $data['height'] = $info[1];
   $data['type'] = $info['mime'];
   return $data;
}
function openImg($path,$type){
      switch($type){
          case 'image/jpeg':
          case 'image/jpg':
          case 'image/pjpeg':
              $img=imagecreatefromjpeg($path);
              break;
          case 'image/png':
          case 'image/x-png':
              $img=imagecreatefrompng($path);
              break;
          case 'image/gif':
              $img=imagecreatefromgif($path);
              break;
          case 'image/wbmp':
              $img=imagecreatefromwbmp($path);
              break;
          default:
              exit('图片类型不支持');
      }
      return $img;
  }

//$water = 'watermark.jpeg';
function water($img,$water,$pos=9,$tm=100){
  $info=getImageInfo($img);
  $logo=getImageInfo($water);
  $dst=openImg($img,$info['type']);
  $src=openImg($water,$logo['type']);
  switch($pos){
      case 1:
          $x=0;
          $y=0;
          break;
      case 2:
          $x=ceil(($info['width']-$logo['width'])/2);
          $y=0;
          break;
      case 3:
          $x=$info['width']-$logo['width'];
          $y=0;
          break;
      case 4:
          $x=0;
          $y=ceil(($info['height']-$logo['height'])/2);
          break;
      case 5:
          $x=ceil(($info['width']-$logo['width'])/2);
          $y=ceil(($info['height']-$logo['height'])/2);
          break;
      case 6:
          $x=$info['width']-$logo['width'];
          $y=ceil(($info['height']-$logo['height'])/2);
          break;
      case 7:
          $x=0;
          $y=$info['height']-$logo['height'];
          break;
      case 8:
          $x=ceil(($info['width']-$logo['width'])/2);
          $y=$info['height']-$logo['height'];
          break;
      case 9:
          $x=$info['width']-$logo['width'];
          $y=$info['height']-$logo['height'];
          break;
      case 0:
      default:
          $x=mt_rand(0,$info['width']-$logo['width']);
          $y=mt_rand(0,$y=$info['height']-$logo['height']);
          break;
  }
   imagecopymerge($dst,$src,$x,$y,0,0,$logo['width'],$logo['height'],$tm);
   header ('Content-Type:image/jpeg');
   imagejpeg($dst);
   imagedestory($dst);
   imagedestory($src);
}
?>



Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!