【问题标题】:how to re-save image after cropping with php and zend?用php和zend裁剪后如何重新保存图像?
【发布时间】:2012-04-16 20:37:40
【问题描述】:

我有一个将我的图片保存到磁盘的功能:

public function uploadToDiskMulty($folderPath, $filename)
{
    // create the transfer adapter
    // note that setDestiation is deprecated, instead use the Rename filter
    $adapter = new Zend_File_Transfer_Adapter_Http();
    $adapter->addFilter('Rename', array(
            'target'    => $filename,
            'overwrite' => true
    ));

    // try to receive one file
    if ($adapter->receive($folderPath)) {
        $message = "success";
    } else {
        $message = "fail";
    }

    return $message;
 }

然后我有一个裁剪图像的功能

public function uploadCroppedImage($image, $x, $y, $w, $h)
{
    $targ_w = 200;
    $targ_h = 300;
    $jpeg_quality = 90;


    $img_r = imagecreatefromstring(file_get_contents($image));
    $dst_r = ImageCreateTrueColor( $targ_w, $targ_h );

    imagecopyresampled($dst_r, $img_r, 0, 0, $x, $y, $targ_w, $targ_h, $w, $h);
}

$image = http://test.com/test_folder/example.jpg

$folderPath = /var/www/media/test_folder/

还有$filename = example.jpg

我的问题是我需要裁剪后的图像路径,因此我可以通过 uploadToDiskMulty 函数运行它。

imagecopyresampled 返回真或假。

有什么想法吗?

谢谢

【问题讨论】:

    标签: php zend-framework image-processing crop


    【解决方案1】:

    您可以使用imagejpeg() 输出它,或者您需要的等效类型。

    imagejpeg($dst_r, 'somepath/someimg.jpg');
    

    【讨论】:

    • 它会保存它吗?如果我通过我的服务器路径/var/www/media/...
    • 你可以使用任何你想要的路径。
    • 嗯,我有这个imagejpeg($dst_r, $image, 90);,但它似乎没有覆盖原始文件
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    相关资源
    最近更新 更多