• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[PHP] Image Class

Hamar

BETA Tester
I was hella bored last night so i decided to help myself in future by making this class,
however there's still a lot of stuff to cover & this thread is more about asking your opinion about my class rather than "sharing or releasing" thread.

Ok so here's the class

Code:
<?php
// Made by Hammer/Hamar Asd Asd Asd HUehhuehuehue
class SignatureImage {
    //put your code here
    private $image;
    private $width;
    private $height;
    private $_transparent;
    
    function __construct($width, $height, $transparent) 
    {
        $this->image = imagecreatetruecolor($width, $height);
        if($transparent)
            $this->CreateTransParentColor(34, 34, 34);
        //imagecolortransparent($this->image, $this->GetColor($transparent));
        
        $this->width = $width;
        $this->height = $height;
        $this->_transparent = $transparent;
    }
    
    function InsertText($text, $fontSize, $positionX, $positionY, $color) // Inserts Arial Text Or uses PHP fonts, .gdf
    {
        imagestring($this->image, $fontSize, $positionX, $positionY, $text, $color);
    }

    function InsertImage($image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
    {
        imagecopyresized($this->image, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    }
    
    // Get Functions
    function GetWidth()
    {
        return $this->width;
    }
    
    function GetHeight()
    {
        return $this->height;
    }
    
    function GetImage()
    {
        return $this->image;
    }
    
    function IsTransParent()
    {
        return $this->_transparent;
    }

    function LoadFont($path)
    {
        $font = imageloadfont($path);
        return $font;
    }
    
    // Create Functions.
    
    function CreateColor($red, $green, $blue)
    {
        return imagecolorallocate($this->image, $red, $green, $blue);
    }
    
    function CreateTransParentColor($red, $green, $blue)
    {
        imagecolortransparent($this->image, $this->CreateColor($red, $green, $blue));
    }
    
    function CreateRectangle($x1, $y1, $x2, $y2, $color)
    {
        imagefilledrectangle($this->image, $x1, $y1, $x2, $y2, $color);
    }
    
    function GetHorizontalMiddle($string, $font_size)
    {
        return (($this->width / 2) - (imagefontwidth($font_size)*strlen($string)));
    }
    
    function GetVerticalMiddle($font_size)
    {
        return (($this->height / 2) - imagefontheight($font_size));
    }
}
?>

And here's my index.php made by using this class:
Code:
<?php

include('SignatureImage.php');

header('Content-Type: image/png');

$testImage = imagecreatefrompng("images/background/2.png");

$signature = new SignatureImage(1366, 768, true);

$signature->InsertImage($testImage, 0, 0, 0, 0, $signature->GetWidth(), $signature->GetHeight(), $signature->GetWidth(), $signature->GetHeight());

$text = "Hamar";

$signature->InsertText($text, $signature->LoadFont("fonts/neuropol.gdf"), $signature->GetHorizontalMiddle($text, 24), $signature->GetVerticalMiddle(24), $signature->CreateColor(117, 112, 200));

imagepng($signature->GetImage());

?>

Result:
st5xj5.jpg
 
Top