1

ファイルのアップロードとテキスト入力を許可するコードがあります。アップロードされたファイルを imagacreatefromjepg と imagecopymerge で使用します。アップロードしたファイルのサイズを 255x175 の特定のサイズに変更したいと考えています。どのように私はそれを作ることができますか? 持っているものは次のとおりです。

        $now = time();
    while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
    {
        $now++;
    }

    // now let's move the file to its final and allocate it with the new filename
    @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
        or error('receiving directory insuffiecient permission', $uploadForm);

    $upload = $uploadFilename;
    $im = imagecreatefromjpeg("bg.jpg");
    $img2 = imagecreatefromjpeg($upload);
    $black = imagecolorallocate($im, 0, 0, 0);
    $font = 'arialbi.ttf';
    $font2 = 'ariali.ttf';

    imagettftext($im, 24, 0, 50, 280, $black, $font, $title);
    imagettftext($im, 10, 0, 320, 362, $black, $font, $namehere);

    imagecopymerge($im, $img2, 30, 350, 0, 0, imagesx($img2), imagesy($img2), 100);

    $date_created = date("YmdHis");//get date created
    $img_name = "-img_entry.jpg"; //the file name of the generated image
    $img_newname = $date_created . $img_name; //datecreated+name
    $img_dir =dirname($_SERVER['SCRIPT_FILENAME']) ."/". $img_newname; //the location to save the image 
    imagejpeg($im, $img_dir , 80); //function to save the image with the name and quality

    $newpath = "/home3/site/public_html/mainfolder/image_entry/";//path to another folder
    $newdir = $newpath.$img_newname;
    copy ($img_dir, $newdir); //copy to new folder

    imagedestroy($im);

これを修正するのを手伝ってくれることを願っています。Resize image before uploading PHPPhp resize width fixの投稿を raed しました。しかし、私の場合、それを適用する方法がわかりません。助けてくれてありがとう。

4

1 に答える 1