# 图片转换pdf 解决方案:https://stackoverflow.com/questions/21217593/create-pdf-from-png-with-imagemagick 把`imagecreatefrompng`替换成你的图片格式, 直接输出pdf文件 ```php function image2pdf($image) { $yourPngImage = imagecreatefrompng($image); $im = new Imagick(); ob_start(); imagepng($yourPngImage); $image_data = ob_get_contents(); ob_end_clean(); // Get image source data $im->readimageblob($image_data); $im->setImageFormat('pdf'); header("Content-Type: application/pdf"); echo $im; } image2pdf('./woc.png'); ``` ## 帮助 - [安装ImageMagick扩展出现configure: error: not found. Please provide a path to MagickWand-config or Wand- config program](https://www.cnblogs.com/gy1010/p/5970016.html) - `yum install ImageMagick-devel`才对, 各个版本之间可能有差异. 可以搜索一下