【问题标题】:PHP - save a converted image into a folderPHP - 将转换后的图像保存到文件夹中
【发布时间】:2013-12-20 10:39:33
【问题描述】:

我正在尝试通过 php 函数 IMG_FILTER_GRAYSCALE 将 jpeg 图像转换为黑白(灰度)。 它工作正常,但我想将图像保存到文件夹中。

代码下方:

$im = imagecreatefromjpeg('pathtomyimage/myimage.jpg');
if($im && imagefilter($im, IMG_FILTER_GRAYSCALE)) {
 header('Content-Type: image/jpeg');
 imagejpeg($im);
} else 
 print 'Error during the b & w conversion';

毕竟很简单...

通过这种方式,它会在屏幕上打印黑白图像,我可以在浏览器上看到它,但我无法将其保存到文件夹中(例如 img/bw/myimage.jpg)。

有办法吗?我该怎么做?

【问题讨论】:

    标签: php gd image-conversion gdlib


    【解决方案1】:

    来自the manual

    imagejpeg($im, 'img/bw/myimage.jpg');
    

    【讨论】:

    • 如此简单实用!非常感谢! :) :)
    【解决方案2】:

    您可以通过这种方式使用 imagejpeg 将图像存储到文件夹中:

    imagejpeg($image, "/path/to/store/file.jpg");
    

    【讨论】:

      【解决方案3】:

      你可以这样使用

      $tmp=imagecreatetruecolor($newwidth,$newheight);
      
          $newwidth1=120;
          $newheight1=150;
          $tmp1=imagecreatetruecolor($newwidth1,$newheight1);
      
          imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,
           $width,$height);
      
          imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1, 
          $width,$height);
      
          $filename = "../Advertisement/". $_FILES['img']['name'];
          $filename1 = "../Advertisement/small". $_FILES['img']['name'];
      
          $filename2 = $_FILES['img']['name'];
          imagejpeg($tmp,$filename,100);
          imagejpeg($tmp1,$filename1,100);
      
          imagedestroy($src);
          imagedestroy($tmp);
          imagedestroy($tmp1);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-03-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-17
        相关资源
        最近更新 更多