我是php的新手,我正在WordPress上建立一个网站。它有一个页面,用户将选择三个选项并生成图形。然后可以在Facebook和Twitter上共享此图形。我已经能够生成并保存图像,但问题是我无法在类似于此网站的网址上显示https://democrats.org/my-vote
我使用php GD生成图像,我在functions.php中创建了一个php函数。这是我的图像生成代码。
$stamp = imagecreatefrompng('images/border_logo.png');
$im = imagecreate(1700, 800);
$font = '/images/proximanova-sbold.ttf';
$white = imagecolorallocate($im, 255, 255, 255);
$blue = imagecolorallocate($im, 62, 193, 201);
$text_length = 30;
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 560;
$marge_bottom = 200;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
$xpos_a = 740;
$ypos_a = 100;
$string_a = "I want";
$black = imagecolorallocate($im, 40, 40, 40);
$xpos_b = 600;
$ypos_b = 150;
$string_b = $_POST['favorite'][0].",";
$sig_b = wordwrap($string_b, $text_length, "<br />", true);
$blue = imagecolorallocate($im, 62, 193, 201);
$xpos_c = 600;
$ypos_c = 225;
$string_c = $_POST['favorite'][1].",";
$sig_c = wordwrap($string_c, $text_length, "<br />", true);
$xpos_d = 600;
$ypos_d = 300;
$string_d = $_POST['favorite'][2].",";
$sig_d = wordwrap($string_d, $text_length, "<br />", true);
$xpos_e = 620;
$ypos_e = 380;
$string_e = 'and that is why I support';
$xpos_f = 700;
$ypos_f = 420;
$string_f = 'ABCD';
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
imagettftext($im, 25, 0, $xpos_a , $ypos_a, $black,$font,$string_a);
$text_b = str_replace('<br />', "\n", $sig_b);
imagettftext($im, 25, 0, $xpos_b, $ypos_b, $blue, $font, $text_b );
$text_c = str_replace('<br />', "\n", $sig_c);
imagettftext($im, 25, 0, $xpos_c, $ypos_c, $blue, $font, $text_c);
$text_d = str_replace('<br />', "\n", $sig_d);
imagettftext($im, 25, 0, $xpos_d, $ypos_d, $blue, $font, $text_d);
imagettftext($im, 25, 0, $xpos_e, $ypos_e, $black, $font, $string_e);
imagettftext($im, 25, 0, $xpos_f, $ypos_f, $black, $font, $string_f);
imagefill($im, 0, 0, $white);
$imgFolderPAth = "/images/";
$imagename = date('m-d-Y_hia')."_image.jpg";
// Save the image as 'simpletext.jpg'
$data1 = imagejpeg($im, $imgFolderPAth . $imagename,100);
// Free up memory
imagedestroy($im);
$response = array('msg'=>'', 'response'=>'success', 'imgname'=>$imagename);
echo json_encode($response);
exit();
}