2014-09-23 2 views
0

이미 서버에 업로드 된 이미지에서 새 이미지를 만듭니다. 새 이미지를 내 서버의 다른 폴더에 업로드하고 싶습니다. 아래 코드로 이미지를 만듭니다. 어떻게 $ jpg_image를 폴더에 업로드 할 수 있습니까?imagecreatefromjpeg에서 만든 이미지를 서버로 업로드하려면 어떻게해야합니까?

<?php 
    $myu="a"; 
    $time = time(); 
    $ip=$_SERVER['REMOTE_ADDR']; 
    $hour= date("H"); 
    $minute =date("i"); 
    $day = date("d"); 
    $month = date("m"); 
    $year = date("Y"); 
    $mysex =$_SESSION['se']; 
    $cappic = $_POST['cappic']; 
    $usttxt = $_POST['ust']; 
    $alttxt = $_POST['alt']; 
    $altfont = $_POST['altfont']; 
    $ustfont = $_POST['ustfont']; 


    // Create Image From Existing File 
    $jpg_image = imagecreatefromjpeg("image.jpg"); 
    list($width, $height) = getimagesize("image.jpg"); 

    // Allocate A Color For The Text 
    $white = imagecolorallocate($jpg_image, 255, 255, 255); 
    $color2 = imagecolorallocate($jpg_image, 0, 0, 0); 

    // Set Path to Font File 
    $font_path = 'impact.ttf'; 

    // Set Text to Be Printed On Image 
    $text = $usttxt; 
    $fs = $ustfont; 
    $dimensions = imagettfbbox($fs, 0, $font_path, $text); 
    $loc1 = $width-$dimensions[2]; 
    $loc1 = $loc1/2; 
    $bot= $fs+10; 


    // Print Text On Image 
    imagettftext($jpg_image, $fs, 0, $loc1, $bot+2, $color2, $font_path, $text); 
    imagettftext($jpg_image, $fs, 0, $loc1, $bot-2, $color2, $font_path, $text); 
    imagettftext($jpg_image, $fs, 0, $loc1-2, $bot, $color2, $font_path, $text); 
    imagettftext($jpg_image, $fs, 0, $loc1+2, $bot, $color2, $font_path, $text); 
    imagettftext($jpg_image, $fs, 0, $loc1, $bot, $white, $font_path, $text); 


    $text2 = $alttxt; 
    $fs = $altfont; 
    $dimensions2 = imagettfbbox($fs, 0, $font_path, $text2); 
    $loc2 = $width-$dimensions2[2]; 
    $loc2 = $loc2/2; 
    $bot=$height-20; 

    // Print Text On Image 
    imagettftext($jpg_image, $fs, 0, $loc2, $bot+2, $color2, $font_path, $text2); 
    imagettftext($jpg_image, $fs, 0, $loc2, $bot-2, $color2, $font_path, $text2); 
    imagettftext($jpg_image, $fs, 0, $loc2-2, $bot, $color2, $font_path, $text2); 
    imagettftext($jpg_image, $fs, 0, $loc2+2, $bot, $color2, $font_path, $text2); 
    imagettftext($jpg_image, $fs, 0, $loc2, $bot, $white, $font_path, $text2); 

    // Send Image to Browser 
    imagejpeg($jpg_image); 
    imagedestroy($jpg_image); 

    // Clear Memory 
    ?> 
+0

[복사] (http://php.net/manual/en/function.copy.php)? –

+0

copy ($ jpg_image, "/ upload_folder/aaa.jpg")를 시도했지만 작동하지 않았습니다. 어쩌면 내가 뭔가 잘못한거야? –

+0

리소스가 아닌 원본 _filename_ 이미지를 넣어야합니다. –

답변

0

체크 아웃 file_put_contents()here

예.)

file_put_contents('folder/folder_2/' . $filename, $file); 
+0

file_put_contents ('/ ul /'. $ jpg_image, "aaa.jpg"); 나는 이것을 시도했으나 작동하지 않았다. –

+0

yah는 작동 할 것이다.'aaa.jpg '는 업로드하려는 파일이고'$ jpg_image'는 당신이 저장하고자하는 파일의 이름이다. – Wold

+0

나는 이것을 시도했다 .. file_put_contents ('/ ul/aaaa.jpg', $ jpg_image); $ jpg_image가 imagecreatefromjpeg로 생성 되었기 때문에 나에게 적합하지 않습니다. –

0

나는 imagejpeg의 경로()을 해결 ... 모든 답변에 대한 감사를 설정, 해결책을 발견했다.

관련 문제