PHP imagecopyresampled似乎没有缩放调整大小图像

时间:2013-10-12 05:17:17

标签: php image image-resizing

这是我的代码,我没有看到我的问题......我会感谢你的帮助!

现在上传更改质量并复制到我的目录,但像素在大图像或小图像上保持不变

不知道我的问题在哪里,我已经检查了几十个例子,看起来像我的代码,我的任何帮助都会很棒!

    //Upload Directory Build
    $uploaddir = './images/projects_data/' . $_POST['table'] . '/' . $id;
    $uploadfile = $uploaddir . '/' . $db_picture;

if (isset($_FILES['images']['name'])) {
//Make Full Directory
if (!file_exists($uploaddir . '/full')) {
mkdir($uploaddir . '/full', 0775, true);
}

//Upload Full Size Thumbnails
foreach ($_FILES['images']['error'] as $key => $error) {
    if ($error == UPLOAD_ERR_OK) {
    $tmp_name = $_FILES['images']['tmp_name'][$key];
    $name = $_FILES['images']['name'][$key];

    //Max Height Width
$maxwidth = 100;

    //Read filetype  
        $i = strrpos($name,".");  
    if (!$i) { return ""; }  
    $l = strlen($name) - $i;  
    $extension = substr($name,$i+1,$l);  
    $extension = strtolower($extension);

    if ($extension=="jpg" || $extension=="jpeg" || $extension=="pjpeg" ) {$modifiedimage = imagecreatefromjpeg($tmp_name);} 
elseif ($extension=="png") {$modifiedimage = imagecreatefrompng($tmp_name);} 
elseif ($extension=="gif") {$modifiedimage = imagecreatefromgif($tmp_name);}  

list($width,$height)=getimagesize($tmp_name);  

    //Change dimensions  
    $newwidth = $maxwidth;  
    $newheight = ($height/$width)*$newwidth;  

//Create Image And Copy
    $newdim = imagecreatetruecolor($newwidth,$newheight);  
    imagecopyresampled($newdim,$modifiedimage,0,0,0,0,$newwidth,$newheight,$width,$height);  
    imagejpeg($modifiedimage,$uploaddir . '/full/' . $name,60);  

    // Remove temp images  
    imagedestroy($modifiedimage);  
    imagedestroy($newdim);  

    //move_uploaded_file($tmp_name, $uploaddir . '/full/' . $name);
echo '<span class="mainpagefontadmin">Project Photo Uploaded - Data Saved to: ' . $uploaddir . '/full/' . $name . '</span><br>';

    }
}

0 个答案:

没有答案