2016-05-20 7 views
0

PHPでイメージのサイズを変更しようとしています。PHPでimagecopyresampledの後にmove_uploaded_fileを作成します

しかし、私はそれに最後のディレクトリをtmp_fileファイルを移動するmove_uploaded_file機能を使用することができますどのようにすべてのこの仕事の後?

$image = imagecreatefromjpeg($_FILES['REG_Image']['tmp_name']); 

// Target dimensions 
$max_width = 1014; 
$max_height = 768; 

// Get current dimensions 
$old_width = imagesx($image); 
$old_height = imagesy($image); 

if($old_width > $max_height) { 

    // Calculate the scaling we need to do to fit the image inside our frame 
    $scale = min($max_width/$old_width, $max_height/$old_height); 

    // Get the new dimensions 
    $new_width = ceil($scale*$old_width); 
    $new_height = ceil($scale*$old_height); 

    // Create new empty image 
    $new = imagecreatetruecolor($new_width, $new_height); 

    // Resize old image into new 
    imagecopyresampled($new, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height); 

} 

ありがとう:

は、ここに私のコードです。

答えて

0

あなたがimage.jpegとして指定した新しいパスにイメージを保存します代わりに

imagecopyresampled($new, $image, 0, 0, 0, 0, $new_width,$new_height, $old_width, $old_height); 
imagejpeg($new, "/path/to/image.jpeg"); 

この後imagejpegを使用することができます。 PNGイメージを出力する場合は、imagepngも使用できます。

関連する問題