PHP 图片上传,压缩,保存到服务器有关问题

WBOY
Release: 2016-06-13 13:33:51
Original
873 people have browsed it

PHP 图片上传,压缩,保存到服务器问题?
很简单上传服务器,从临时文件,'tmp_name'得到图片,
然后压缩。

$dstimage = imagecreatetruecolor($dst_w, $dst_h);
imagecopyresampled($dstimage,$srcimage,$dst_x, $dst_y , $src_x,$src_y ,$dst_w, $dst_h, $src_w,$src_h);
imagedestroy($srcimage);

查找了好久都没有找到如何,保存内存中的图片 $dstimage 的方法?

------解决方案--------------------

PHP code

/** 打开输出缓冲 **/
ob_start();

/** 输出图像 **/
imagepng($dstimage);

/** 获取缓冲区内容 **/
$img = ob_get_contents();

/** 清空输出缓冲 **/
ob_end_clean();

/** 然后把$img保存到文件就行了 **/
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
PHP code
// 保存的位置
$file = "/image/hello.png"
imagepng($dstimage, $file); <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!