duanji9481 2017-03-05 20:41
浏览 96

将水印与PHP对齐到左上角而不是右下角

I tried many ways to change coordinates of watermark image to top left corner but I can't understand which of variables defines top,left,right and bottom corner.

I hope you can help

 //Source folder where all images are placed
 $source="source";

 //Destination folder where all images with watermark will be copied
 $destination="destination";

 //Creating an image object of watermark image
 $watermark=imagecreatefrompng("watermark.png");

 //Margin of watermark from right and bottom of the main image
 $margin_right=10;
 $margin_bottom=10;

 //Height ($sy) and Width ($sx) of watermark image
 $sx=imagesx($watermark);
 $sy=imagesy($watermark);

 //Get list of images in source folder
 $images=array_diff(scandir($source), array('..', '.'));

 foreach($images as $image){
    //Create image object of main image
    $img=imagecreatefromjpeg($source.'/'.$image);

    //Copying watermark image into the main image
    imagecopy($img, $watermark, imagesx($img) - $sx - $margin_right, imagesy($img) - $sy - $margin_bottom, 0, 0, $sx, $sy);

    //Saving the merged image into the destination folder
    imagejpeg($img, $destination.'/'.$image,100);

    //Destroying the main image object
    imagedestroy($img);
}

 //Destroying watermark image object
 imagedestroy($watermark);

 ?>
  • 写回答

1条回答 默认 最新

  • dongyue9860 2017-03-05 20:46
    关注

    Well it's in your code !

    //Margin of watermark from right and bottom of the main image
     $margin_right=10;
     $margin_bottom=10;
    

    I'm not sure how your script work, but you may add :

    $margin_left=10;
    $margin_top=10;
    

    And remove :

    $margin_right=10;
    $margin_bottom=10;
    

    It's not really related to PHP ! It looks like CSS configuration !

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度