上传时获取pdf文件缩略图
Getting pdf file thumnail when uploading
我正在开发我的教育网站。我使用简单的 php 代码上传我的 pdf 文件,例如书籍、工作表...我希望 pdf 缩略图自动显示在我的 read.php 页面的链接上。我可以这样做吗?请帮忙用简单的php方式解释一下。谢谢。
您将需要使用这两个库:
https://sourceforge.net/projects/ghostscript/
安装 GhostScript 后:
$thumbnails = new imagick('pdf_file.pdf[0]'); // the name of ur pdf file [0] represents page 1
$thumbnails ->setImageFormat('jpg'); // the output format of thumbnails
header('Content-Type: image/jpeg');
echo $thumbnails; // this will finally output ur thumbanil
正在安装 GhostScript: 参考:https://gist.github.com/leomelzer/3949356
- 你安装了 Ghostscript,对吧?否则
sudo apt-get install ghostscript
- 这很重要,它会安装必需的 headers(iapi.h 等),但默认的 Ghostscript 包中没有:
sudo apt-get install libgs-dev
- 我还需要
sudo apt-get install gs-esp
- 对我来说,ImageMagick 的预编译版本从不接受 Ghostscript,所以让我们删除它:
sudo apt-get --purge remove imagemagick
- 获取 ImageMagick 的源代码,解压它,
cd ImageMagick-xx
./configure --with-gslib=yes
[以及您还需要什么]
- 在靠近底部的输出中确认 gslib yes yes and not gslib yes no
make
make install
- 运行
convert -list configure | grep DELEGATES => DELEGATES bzlib djvu freetype gs jpeg jng jp2 lcms png tiff x11 xml zlib
- 看到里面的 gs 了吗?你明白了!
我正在开发我的教育网站。我使用简单的 php 代码上传我的 pdf 文件,例如书籍、工作表...我希望 pdf 缩略图自动显示在我的 read.php 页面的链接上。我可以这样做吗?请帮忙用简单的php方式解释一下。谢谢。
您将需要使用这两个库:
https://sourceforge.net/projects/ghostscript/
安装 GhostScript 后:
$thumbnails = new imagick('pdf_file.pdf[0]'); // the name of ur pdf file [0] represents page 1
$thumbnails ->setImageFormat('jpg'); // the output format of thumbnails
header('Content-Type: image/jpeg');
echo $thumbnails; // this will finally output ur thumbanil
正在安装 GhostScript: 参考:https://gist.github.com/leomelzer/3949356
- 你安装了 Ghostscript,对吧?否则
sudo apt-get install ghostscript
- 这很重要,它会安装必需的 headers(iapi.h 等),但默认的 Ghostscript 包中没有:
sudo apt-get install libgs-dev
- 我还需要
sudo apt-get install gs-esp
- 对我来说,ImageMagick 的预编译版本从不接受 Ghostscript,所以让我们删除它:
sudo apt-get --purge remove imagemagick
- 获取 ImageMagick 的源代码,解压它,
cd ImageMagick-xx
./configure --with-gslib=yes
[以及您还需要什么]- 在靠近底部的输出中确认 gslib yes yes and not gslib yes no
make
make install
- 运行
convert -list configure | grep DELEGATES => DELEGATES bzlib djvu freetype gs jpeg jng jp2 lcms png tiff x11 xml zlib
- 看到里面的 gs 了吗?你明白了!