изображение не отображается: php gd с пользовательской функцией

Я здесь новичок, поэтому у меня есть специальная функция для вычисления ширины и высоты imagettftext(), но когда я включаю файл, содержащий эту функцию, он отображает только поврежденное изображение, и я не знаю, что его вызывает... .

это мой файл last.php (он якобы отображает изображение с текстом)

<?php

include ('function-location.php');
$location = new  lokasyon;
$x = $location->text_location_x();
$y = $location->text_location_y();  


$img = imagecreatefromjpeg('\xampp\htdocs\1\q.jpg');

$font_size = 10;
$white = imagecolorallocate($img, 195, 195, 195);
$font_path = 'C:\Windows\Fonts\Arial.ttf';
$text = "Fashion.com";

$angle = 0 ; 


echo $x." & ".$y;

//                              Y     X
imagettftext($img, $font_size, 0, $y, $x, $white, $font_path, $text);

header('Content-type: image/jpeg');

imagejpeg($img);
imagedestroy($img);

?>

это моя функция-location.php

<?php
class lokasyon{

public $location;
public $font_size;
public $img;

public function __construct(){

}   

function text_location_x($x=''){    
    $location = $_POST['Location'];
    $img = imagecreatefromjpeg('\xampp\htdocs\1\q.jpg');
    $font_size = 10;

    if ($location == "Top Left"){
        $x = (imagesx($img)-$font_size);
        return $x;
    }
    elseif ($location == "Top Right"){
        $x = (imagesx($img)-$font_size);
        return $x;
    }
    elseif ($location == "Bottom Left"){
        $x = 0;
        return $x;
    }
    else{
        $x =(imagesx($img)-$font_size);
        return $x;
    }
}

function text_location_y($y=''){    
    $location = $_POST['Location'];
    $img = imagecreatefromjpeg('\xampp\htdocs\1\q.jpg');
    $font_size = 10;

    if ($location == "Top Left"){
        $y = 0; 
        return $y;
    }
    elseif ($location == "Top Right"){
        $y = 0;
        return $y;
    }
    elseif ($location == "Bottom Left"){
        $y = (imagesy($img)-$font_size);
        return $y;
    }
    else{
        $y =(imagesy($img)-$font_size);
        return $y;
    }
  }
}   
?>

Я новичок в этом..


person Aivimae Alderite    schedule 11.05.2015    source источник


Ответы (1)


Я решил это, удалив включение в файл last.php и добавив функцию непосредственно в last.php....

<?php


function text_location_x_height($x=''){ 
    $location = $_POST['Location'];
    $img = imagecreatefromjpeg('\xampp\htdocs\1\q.jpg');
    $font_size = 10;

    if ($location == "Top Left"){
        $z = (imagesy($img)/2);
        $x = ($z - $z)+10;
        return $x;
    }
    elseif ($location == "Top Right"){
        $z = (imagesy($img)/2)/2;
        $x = ($z - $z)+10;
        return $x;
    }
    elseif ($location == "Bottom Left"){
        $z = (imagesy($img)/2);
        $w = $z/2;
        $x = ($z + $w) + $w;
        return $x;
    }
    elseif ($location == "Bottom Right"){
        $z = (imagesy($img)/2);
        $w = $z/2;
        $x = ($z + $w) + $w;
        return $x;
    }
    else{
        $x =  (imagesy($img)/2);
        return $x;
    }
}

function text_location_y_width($y=''){  
    $location = $_POST['Location'];
    $img = imagecreatefromjpeg('\xampp\htdocs\1\q.jpg');
    $font_size = 10;

    if ($location == "Top Left"){
        $y = 0; 
        return $y;
    }
    elseif ($location == "Top Right"){
        if(imagesx($img) >= 1000){
            $w = (imagesx($img)/2)/2;
            $q = $w/2;
            $r = $q/2;
            $s = $r/2;
            $y = (imagesx($img)-$r)-$s;
            return $y;
        }
        else{
            $z = (imagesx($img)/2)/2;
            $y = ($z + $z)+ $z + 20;
            return $y;

        }
    }
    elseif ($location == "Bottom Left"){
            $y = 0;
            return $y;              
    }
    elseif ($location == "Bottom Left"){
        if (imagesx($img) >= 1000){
            $w = (imagesx($img)/2)/2;
            $q = $w/2;
            $r = $q/2;
            $s = $r/2;
            $y = (imagesx($img)-$r)-$s;
            return $y;
        }
        else{
            $z = (imagesx($img)/2)/2;
            $y = ($z + $z)+ $z + 20;
            return $y;
        }
    }
    else{
        $y = (imagesx($img)/2)-$font_size*5; 
        return $y;
    }
}
$x = text_location_x_height();
$y = text_location_y_width();   

$img = imagecreatefromjpeg('\xampp\htdocs\1\q.jpg');

$font_size = 10;
$white = imagecolorallocate($img, 195, 195, 195);
$font_path = 'C:\Windows\Fonts\Arial.ttf';
$text = "Fashion.com";


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

header('Тип контента: изображение/jpeg');

imagejpeg($img);
imagedestroy($img);?>
person user4886631    schedule 11.05.2015