开发者

Creating a PHP script from BASH code to run on Windows

I have this line of code:

convert 1234_Page_1_....png 1234_Page_2_....png output.pdf 

This merges the listed pngs to a single pdf (using ImageMagick). I have a bunch of PNG files in this format. I would like to create a loop in PHP to run through the convert/merge action on all the files that I have. For all the files that have the same number before the "Page", I would like them to be merged to one PDF with that same number as a name. Sometimes there are more than two pages to convert.

For this example, I would like "1234_Page_1_....png" and "1234_Page开发者_开发百科_2_....png" to result as 1234.pdf. And I would like files "1235_Page_1_....png" and "1235_Page_2_....png" to result as 1235.pdf, and so on.

Here's what I've been told is the BASH way to handle the problem:

for i in `seq 1234 1350` ; do convert ${i}_Page_*.png ${i}_output.pdf ; done 

I would like to have this done in a PHP script that I can run on Windows.

Thanks in advance, Jake


The reason you're getting that error message is that you edited the script using a Windows editor and then tried to run it in a Unix-type environment. Run dos2unix scriptname and the Windows line endings will be converted to Unix line endings. No more $'\r' errors. Also, in Bash use for i in {1234..1350} - there's no need to use seq.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜