在zend-framework上调整图像大小

时间:2012-06-07 11:47:18

标签: image zend-framework resize

我徘徊是Zend Framework中图像大小调整的一些特殊工具? 或者我应该使用这样的代码:

$upload = new Zend_File_Transfer_Adapter_Http();
try {
    $upload->receive();
} catch (Zend_File_Transfer_Exception $e) {
    $e->getMessage();
}
$im_org = imageCreateFromJpeg($upload);
$im_bg = imageCreateTrueColor(300, 300);
imageCopyResampled($im_bg, $im_org, 0, 0, 0, 0, 300, 300, imageSX($im_org), imageSY($im_org));
imageJpeg($im_bg, "pict/" . $id . "_bg.jpg", 100);
imagedestroy($im_org);
imagedestroy($im_bg);

谢谢!

2 个答案:

答案 0 :(得分:7)

您可以尝试Zend_Filter_ImageSize

最简单的例子:

<?php
require_once 'Zend/Filter/ImageSize.php';
$filter = new Zend_Filter_ImageSize();
$output = $filter->setHeight(100)
    ->setWidth(200)
    ->filter('./orig.jpg');

header('Content-Type: image/jpeg');
$fh = fopen($output, 'r');
fpassthru($fh);
fclose($fh);
?>

答案 1 :(得分:0)

我建议使用class.upload.php from verot.net等实体库。

它应该很容易集成到Zend Framework中,你可以找到more complex example integration on this blog post