dongxiaoguang9108 2013-05-15 22:34
浏览 39

在prestashop 1.3.1中创建图像

I am doing products import php script for prestashop 1.3.1 and I have one problem. I have URL of picture, but i dont know hoe to use it and make different images (thumbnails it is called I think).

If I have picture http://www.nordix.cz/img/p/824-2268.jpg what I must write in PHP to make thubnails?

Thank you so much for tips!

  • 写回答

2条回答 默认 最新

  • dongyan3853 2013-05-16 08:39
    关注

    To process an image (create thumbs) first you have to copy it to a local directory. You can't do any processing on an image which is on another server or url. So here is how i did it in one of my PS project.

    1) First check if the image exists or not. You can do it by using fopen in read mode, if it returns true, then the file exists. It is a good practice to do it because it will avoid unnecessary calls to the remote server.

     $imageUrl =  "http://www.nordix.cz/img/p/824-2268.jpg";
     @fopen($imageUrl, "r"); 
    

    2) Now you have the image as the fopen returned true, you need to copy the image to the PS temp directory as below

    $tmpName = tempnam(_PS_TMP_IMG_DIR_, 'PS');
    copy($imageUrl , $tmpName);
    

    after the copy function downloads the image to PS temp directory, then you can process that image as you want. Remember that you have to make all processing on $tempName, as it is the file now. $tempName is like $_FILES['imageFieldName']['tmp_name'].

    Thank you

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作