When taking screenshots of the website, CutyCapt, a tool of the server, is used. You can directly use commands on the server to capture and generate pictures of the specified URL. However, when using php to execute system commands, it was found that it could not be executed, but commands with help information such as CutyCapt ("/usr/local/cutycapt/CutyCapt/xvfb-run.sh --help") could be executed, but the call was executed# The script of ##System Variables failed. I suspected that it was a permissions issue. I later set the CutyCapt permissions to www, but found that it didn't work. After searching for information, I found that the nginx server would call a shell script when executing the command, and then encounter a permissions problem.
This article mainly introduces the method ofUse php to execute commands using exec
PS. By default, the execexec('xvfb-run --server-args="-screen 0, 1024x768x24" CutyCapt --url=http://www.jb51.net --out=2.jpg');
picture only has the first screen, so crop the picture
yum install ImageMagick
Use convert -crop for cropping
convert -crop 1024x768+0+0 2.jpg 22.jpg
Use convert -resize for image scaling
convert -resize 15%x15% 22.jpg 22.jpg
The above is the detailed content of PHP sample code for implementing web page screenshots by executing the CutyCapt command. For more information, please follow other related articles on the PHP Chinese website!