【问题标题】:copy image to many folder将图像复制到多个文件夹
【发布时间】:2013-04-14 09:55:40
【问题描述】:

我写了一个关于减小图像大小的测试工作代码,当图像上传时,它会从一个文件夹复制到另一个文件夹。它将图像大小减小到 300 的宽度和 300 的高度。

我还想将相同的图像尺寸减小到 100 宽和 100 高,这样我就可以使用最小的图像作为个人资料图片和电子邮件收件箱图像。而另一个在用户相册上的图像为 300,高度为 300。

我希望上传的图片复制到宽度 300 和高度 300 以及 100 和高度 100 的 2 个不同尺寸。

请帮帮我。

            if(move_uploaded_file($this->tem_path, $terger_path)){                  
                $exe = explode(".", $this->filename);
                $ext = $exe[1];
                $w = 300;
                $h = 300;
                $target = SITE_ROOT.DS.$this->img_path.DS.$this->filename;              
                $newcopy = SITE_ROOT.DS.$this->resize.DS.$this->filename; 
                list($w_orig, $h_orig) = getimagesize($target);
                $scale_ratio = $w_orig / $h_orig;
                if (($w / $h) > $scale_ratio) {
                   $w = $h * $scale_ratio;
                } else {
                   $h = $w / $scale_ratio;
                }
                $img = "";
                $ext = strtolower($ext);
                if ($ext == "gif"){ 
                     $img = imagecreatefromgif($target);
                } else if($ext =="png"){ 
                     $img = imagecreatefrompng($target);
                } else { 
                  $img = imagecreatefromjpeg($target);
                }
                $tci = imagecreatetruecolor($w, $h);
                imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
                if(@imagejpeg($tci, $newcopy, 80)){
                //  return true;
                    $terger_path = SITE_ROOT.DS.$this->img_path.DS.$this->filename;
                    return unlink($terger_path) ? true : false;                     
                }                   

            }

【问题讨论】:

    标签: php


    【解决方案1】:

    嗯,这很简单:

    1. 首先调整大小,将其复制到第一个位置。不要删除上传的文件。
    2. 第二次调整大小,复制到其他位置。
    3. 完成清洁(如有必要)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-03
      • 2020-07-30
      • 1970-01-01
      • 2013-03-20
      相关资源
      最近更新 更多