如何将imagecreatefromjpeg创建的图像上传到服务器?

时间:2014-09-23 18:04:58

标签: php

我正在从已上传到服务器的图像创建新图像。我想将新图像上传到我服务器中的另一个文件夹..我使用下面的代码创建图像,如何将$ jpg_image上传到该文件夹​​?

    <?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
    ?>

2 个答案:

答案 0 :(得分:0)

结帐file_put_contents() here

前。)

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

答案 1 :(得分:0)

我找到了解决方案,在imagejpeg()中设置路径解决了它...感谢所有答案。