1
私はPHPを初めて使い、サーバーにアップロードする前にイメージにテキストオーバーレイを追加するのに苦労しています。これは私の現在の機能ですが、画像にテキストを追加していません。イメージにテキストを重ねてサーバーにアップロード
function image_file_upload($conn) {
$target_dir = "../users/images/";
$caption = $_POST['comment'];
$imgFile = $_FILES['user_image']['name'];
$tmp_dir = $_FILES['user_image']['tmp_name'];
$target_file = $target_dir . basename($imgFile);
$uploadOk = 1;
$font_color = bcca;
$background_color = abbc;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$ext = explode('.',$imgFile);
$file = $target_dir . uniqid() . "." . $ext[1];
$uid = 4;
// Check if image file is a actual image or fake image
$check = getimagesize($tmp_dir);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($tmp_dir, $file)) {
$jpg_image = imagecreatefromjpeg($file);
$white = imagecolorallocate($jpg_image, 255, 255, 255);
$font_path = 'simple.ttf';
$text = "This is a Sunset!";
imagettftext($jpg_image, 10, 0, 0, 0, $white, $font_path, $text);
imagejpeg($jpg_image,$file);
$date = date('Y-m-d H:i:s');
insert_into_post($conn, $uid, 1, $date, $file, $background_color, $font_color, 0 , 0, "image", $caption);
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}