duanpo2813 2016-11-13 10:28
浏览 104
已采纳

PHP GD .ico处理

Users of my PHP webapp are permitted to upload PNG and JPEG images. Upload algorithm is following:

  1. check extension by file name parsing
  2. check extension by getimagesize()
  3. recreate image by imagecreatefrompng()/imagepng() (imagecreatefromjpeg()/imagejpeg())
  4. rename image
  5. save to filesystem

Image recreation is used for security. Everything works fine. But now i need this algorithm to handle .ico files. It seems like GD doesn't work with .ico (there is no function like imagecreatefromico()), so i don`t know how to implement step 3 of my algorithm.

Thanks for any help or advice.

  • 写回答

1条回答 默认 最新

  • dran0703 2017-01-22 10:17
    关注

    See https://github.com/lordelph/icofileloader for a composer-installable class which can load .ico files into a GD image.

    For example:

    $loader = new Elphin\IcoFileLoader\IcoFileService;
    $im = $loader->extractIcon('/path/to/icon.ico', 32, 32);
    

    See documentation for other methods of analysing and extracting images from the icon file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥115 关于#python#的问题:未加密前两个软件都可以打开,加密后只有A软件可打开,B软件可以打开但读取不了数据
  • ¥15 在matlab中Application Compiler后的软件无法打开
  • ¥15 想问一下STM32创建工程模板时遇到得问题
  • ¥15 Fiddler抓包443
  • ¥20 Qt Quick Android 项目报错及显示问题
  • ¥15 而且都没有 OpenCVConfig.cmake文件我是不是需要安装opencv,如何解决?
  • ¥15 oracleBIEE analytics
  • ¥15 H.264选择性加密例程
  • ¥50 windows的SFTP服务器如何能批量同步用户信息?
  • ¥15 centos7.9升级python3.0的问题