0

I created a font.php file that is used to preview fonts and I try to include it in a joomla 4 article, but it always returns error 500. -Include some simple php file in joomla article works. -Include the font.php file in another php file (non-Joomla) also works

From this I assume that there is some conflict between my php and joomla. Here is my code so if anyone can help me with this problem:

     <?php

 if(isset($_POST['submit']))
  {
     $font = $_POST['fonts'];
  }
// link to the font file no the server
$fontname = realpath('/code/font/' . $font);

// controls the spacing between text
$i=30;
//JPG image quality 0-100
$quality = 90;

function create_image($user){

        global $fontname;   
        global $quality;
        // Definisanje podrazumevanih vrednosti za ključeve ako nisu postavljeni
if (!isset($user[0])) {
    $user[0] = ['name' => '', 'font-size' => '16', 'color' => 'grey'];
}

if (!isset($user[1])) {
    $user[1] = ['name' => '', 'font-size' => '16', 'color' => 'grey'];
}

if (!isset($user[2])) {
    $user[2] = ['name' => '', 'font-size' => '16', 'color' => 'grey'];
}

        $file = "code/covers/".md5($user[0]['name'].$user[1]['name'].$user[2]['name']).".jpg";  
    
    // if the file already exists dont create it again just serve up the original   
    //if (!file_exists($file)) {    
            

            // define the base image that we lay our text on
            $im = imagecreatefromjpeg("code/pass.jpg");
            
            // setup the text colours
            $color['grey'] = imagecolorallocate($im, 54, 56, 60);
            $color['green'] = imagecolorallocate($im, 55, 189, 102);
            $height = 0;
            // this defines the starting height for the text block
            $y = imagesy($im) - $height - 60;
             $i = 1;
        // loop through the array and write the text    
        foreach ($user as $value){
            // center the text in our image - returns the x value
            $x = center_text($value['name'], $value['font-size']);  
            imagettftext($im, $value['font-size'], 0, $x, $y+$i, $color[$value['color']], $fontname,$value['name']);
            // add 32px to the line height for the next text block
            $i = $i+32; 
            
        }
            // create the image
            imagejpeg($im, $file, $quality);
            
    //}
                        
        return $file;   
}

function center_text($string, $font_size){

            global $fontname;

            $image_width = 600;
            $dimensions = imagettfbbox($font_size, 0, $fontname, $string);
            
            return ceil(($image_width - $dimensions[4]) / 2);               
}



    $user = array(
    
        array(
            'name'=> 'Ashley Ford', 
            'font-size'=>'37',
            'color'=>'grey')
            
    );
    
    
    if(isset($_POST['submit'])){
    
    $error = array();
    
        if(strlen($_POST['name'])==0){
            $error[] = 'Please enter a name';
        }
        

        
    if(count($error)==0){
        
    $user = array(
    
        array(
            'name'=> $_POST['name'], 
            'font-size'=>'100',
            'color'=>'grey')
            
    );      
        
    }
        
    }

// run the script to create the image
$filename = create_image($user);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>BećArt.ba</title>
<style>
input{
    border:1px solid #ccc;
    padding:8px;
    font-size:14px;
    width:150px;
    }
    
.submit{
    width:60px;
    background-color:#FF6;
    padding:3px;
    border:1px solid #FC0;
    margin-top:20px;}   

</style>
</head>
<body>
<img src="<?=$filename;?>?id=<?=rand(0,1292938);?>" width="600" height="170"/><br/><br/>
<ul>
<?php if(isset($error)){
    
    foreach($error as $errors){
        
        echo '<li>'.$errors.'</li>';
            
    }
    
    
}?>
</ul>

<p>Odaberite font, upišite vaše ime i kliknite na dugme "Kreiraj".</p>

<div class="dynamic-form">
<form action="" method="post">

  <label for="fonts">Odaberi font:</label>
  <select name="fonts" id="fonts">
  <option value="arial.ttf">Štampana 1</option>
  <option value="timesnewroman.ttf">Štampana 2</option>
  <option value="Capriola-Regular.ttf">Štampana 3</option>
  <option value="MonotypeCorsiva.ttf">Štampana ukrasna</option>
  </select>
  <br><br>
  
  
<label>Upišite ime</label>
<input type="text" value="<?php if(isset($_POST['name'])){echo $_POST['name'];}?>" name="name" maxlength="15" placeholder="Name"><br/><br><br>
<input name="submit" type="submit" class="btn btn-primary" value="Kreiraj" />
</form>
</div>
</body>
</html>

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.