Imagettftext not working GD PHP

Hello Guys Someone please tell me why imagettftext not working on this image function

<?php

     $font='ComicSansMSRegular.ttf';
     $images='2.jpg';
    list($w, $s, $source_type) = getimagesize($images);

   
    $img = new Img();
    $img->create($w, $s, true);
 
    // first image; crop and merge with base.
    $img2 = new Img('./2.jpg');

    $img->merge($img2, 0, 0);

    // second image; crop and merge with base.
    $img3 = new Img('./1.jpg');
    $img3->circleCrop();
    $img->merge($img3, 25, 100);

    // image text
    $text = 'just a text';
    $text_color = imagecolorallocate($im,255,192,203);
	
	 imagettftext ($img, 40, 0, 698, 435, $text_color, $font, $text);


       $img->render();





    class Img
    {
    public $img;

    public $transparent;

    public $width;

    public $height;

    public function __construct($img = null)
    {
        if (!empty($img)) {
            $this->img = imagecreatefromjpeg($img);
            $this->width = imagesx($this->img);
            $this->height = imagesy($this->img);
            $this->setTransparentColour();
        }
    }

    public function create($width, $height, $transparent)
    {
        $this->img = imagecreatetruecolor($width, $height);
        $this->width = $width;
        $this->height =$height;

        $this->setTransparentColour();

        if (true === $transparent) {
            imagefill($this->img, 0, 0, $this->transparent);
        }
    }

    public function setTransparentColour($red = 255, $green = 0, $blue = 255)
    {
        $this->transparent = imagecolorallocate($this->img, $red, $green, $blue);
        imagecolortransparent($this->img, $this->transparent);
    }

    public function circleCrop()
    {
        $mask = imagecreatetruecolor($this->width, $this->height);
        $black = imagecolorallocate($mask, 0, 0, 0);
        $magenta = imagecolorallocate($mask, 255, 0, 255);

        imagefill($mask, 0, 0, $magenta);

        imagefilledellipse(
            $mask,
            ($this->width / 2),
            ($this->height / 2),
            $this->width,
            $this->height,
            $black
        );

        imagecolortransparent($mask, $black);

        imagecopymerge($this->img, $mask, 0, 0, 0, 0, $this->width, $this->height, 100);

        imagedestroy($mask);
    }

    public function merge(Img $in, $dst_x = 0, $dst_y = 0)
    {
        imagecopymerge(
            $this->img,
            $in->img,
            $dst_x,
            $dst_y,
            0,
            0,
            $in->width,
            $in->height,
            100
        );
    }

    public function render()
    {
        header('Content-type: image/jpg');
        imagejpeg($this->img);
    }
    }

    ?>

is not defined anywhere - did you mean to use $img instead?

what you tell me how to use image text on this function

I would assume that the $im reference in that line needs to be an image but you don’t have an image by that name - everywhere else you are using $img

$img is also not working iys type by mistake but i was try that before

The image resource passed needs to be one created by one of the image create functions. It likely isn’t recognising the value you are passing as being an image resource.

give me any solution how to put text thanks

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.