原创

完整代码:鼠标右键实现命令行裁剪图片及添加水印代码


完整代码:鼠标右键实现命令行裁剪图片及添加水印代码,视频演示地址:
https://www.ixigua.com/7027055168101286437

  1. #!/usr/bin/env php
  2. <?php
  3. //教程1 https://micuu.com/new/2305.html
  4. // cmd /c D:\phpstudy_pro\Extensions\php\php7.3.4nts\php.exe C:\Users\Administrator\Desktop\index.php -a=%1
  5. // echo '您输入的信息是:'.$name."\r\n";
  6. // composer require intervention/image //下载完成后运行命令
  7. // http://image.intervention.io/use/basics //官方文档地址
  8. // $argv 获得所有空格分隔的参数列表
  9. $arg = getopt("a:");
  10. print_r($arg['a'].'\n');
  11. $path = $arg["a"];
  12. require __DIR__.'/vendor/autoload.php';
  13. use Intervention\Image\ImageManagerStatic as Image;
  14. //需要用户输入的字段
  15. $needInput = [
  16. 'width' => "",
  17. 'height' => "",
  18. 'logo' => "",
  19. ];
  20. //字段提示 注意:其中 key 需要和 needinput数组中的 key 对应
  21. $outMsg = [
  22. 'width' => "宽度",
  23. 'height' => "高度",
  24. 'logo' => "水印",
  25. ];
  26. $fs = true; //用户输入状态 当用户灭有输入的时候是true,输入后是false
  27. foreach($needInput as $k => $v){
  28. do{
  29. if($fs){
  30. fwrite(STDOUT,$outMsg[$k]);
  31. $fs = false;
  32. }else{
  33. fwrite(STDOUT,"抱歉,{$outMsg[$k]} 不能为空,请重新输入{$outMsg[$k]}:");
  34. }
  35. $needInput[$k] = trim(fgets(STDIN));
  36. if($needInput[$k] != ''){
  37. $fs = true;
  38. }
  39. }while($needInput[$k] == '');
  40. }
  41. print_r($needInput);
  42. // and you are ready to go ...
  43. $img = Image::make($path)->resize($needInput["width"], $needInput["height"]);
  44. // save file as jpg with medium quality
  45. $res = $img->save($path."副本.jpg", 100);
  46. if($res == true){
  47. echo "图片处理成功";
  48. }else{
  49. echo "图片处理失败";
  50. }
  51. // // create new Intervention Image
  52. // $img = Image::make('public/foo.jpg');
  53. // // paste another image
  54. // $img->insert('public/bar.png');
  55. // // create a new Image instance for inserting
  56. // $watermark = Image::make('public/watermark.png');
  57. // $img->insert($watermark, 'center');
  58. // // insert watermark at bottom-right corner with 10px offset
  59. // $img->insert('public/watermark.png', 'bottom-right', 10, 10);
留言反馈
问题反馈渠道,如有软件无法下载或者其他问题可反馈。【由于某种原因,目前留言不展示】
用户需要登录后才能留言反馈