dourao1896 2012-03-26 00:25
浏览 46

使用PHP中的SimpleImage调整图像大小

I'm using SimpleImage to resize images in PHP. I need to resize the images uploaded via a form using the file browse. I use the following approach to resize the image uploaded via a file browse.

$image=new SimpleImage();
$image->load($_FILES['txt_brand_img']['tmp_name']); //It isn't working.

if($image->getWidth()>500)
{
$image->resizeToWidth(500);
$image->save("images_db/".$filename);
}

It isn't working. I could see somewhat resemble approach here but it didn't work for me. When I upload and save the image in a directory and give the saved file path to the load() function as follows it is working.

$filename=rand(1000,1000000).$_FILES["txt_brand_img"]["name"];
move_uploaded_file($_FILES["txt_brand_img"]["tmp_name"],"images_db/".$filename);

    $image=new SimpleImage();                       
    $image->load("images_db/".$filename);   //It is working.
    if($image->getHeight()>100 || $image->getWidth()>100)
    {                               
            $image->resize(100, 100);
        $image->save("images_db/thumb/".$filename);
    }
    else
    {
        $image->save("images_db/thumb/".$filename); 
    }

May I be using a wrong approach in the previous code snippet? How could the uploaded images be directly resized without saving them using SimpleImage?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用
    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?