0

我的脚本有这个小问题,因为我能够在本地输出我的图像并“将其另存为”,但是当我尝试将文档上传到我的服务器时我无法做到这一点,我需要的是,一旦我点击提交浏览器提醒我要对图像做什么,保存或打开它,这是我的脚本:

<?php $nombre=$_POST['nombre'];
    //Set the Content Type
header('Content-type: image/png'); 


    // Create Image From Existing File
    $jpg_image = imagecreatefromjpeg('fabian.jpg');
        // get image dimensions
 list($img_width, $img_height,,) = getimagesize("fabian.jpg");

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

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

    // Set Text to Be Printed On Image
    $text =strtoupper($nombre);

    // Print Text On Image
    //imagettftext($jpg_image, 75, 0, 50, 400, $white, $font_path, $text);



  // find font-size for $txt_width = 80% of $img_width...
  $font_size = 1; 
  $txt_max_width = intval(0.8 * $img_width);    

  do {

  $font_size++;
  $p = imagettfbbox($font_size,0,$font_path,$text);
  $txt_width=$p[2]-$p[0];
  // $txt_height=$p[1]-$p[7]; // just in case you need it

 } while ($txt_width <= $txt_max_width);

  // now center text...
 $y = $img_height * 0.9 ;// baseline of text at 90% of $img_height
  $x = ($img_width - $txt_width) / 2;

  imagettftext($jpg_image, $font_size, 0, $x, $y, $white, $font_path, $text);



    // Send Image to Browser and Save
 imagepng($jpg_image);

 header("Content-Disposition: attachment; filename=snivel.png");

// Clear Memory
    imagedestroy($jpg_image);

   ?>

这会将图像作为 draw.php 发送到浏览器,但我希望将其保存为snivel.png当浏览器提示我保存文件时,这仅适用于本地,但不适用于我的服务器。

4

0 回答 0