Show DevBest NekoGD ~ The GD library for easier PHPGD implementation.

Jian

Resident Weeb
Contributor
Sep 2, 2011
687
437
I have coded NekoGD in the hopes of getting to know the PHPGD feature better. As I have seen that the current GD functions are a mess and is not friendly to anyone who uses it at all, I have decided to code a library to replace the ruggedness of the standalone GD to a more simpler-to-use fashion.

Currently, there are only the basic features that people normally use. More will be added as I learn.

Background
  • Image from base.
  • Image from color.
  • Transparent background.
Text
  • More friendly text usage on image.
Support For
  • PNG
  • GIF
  • JPEG
You can download or read on how to use NekoGD on the repository!
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
I can't help but think your config function could've been simplified a lot more.

This is what you have:
PHP:
public function config($type, $height = "0", $width = "0") {
    $this->height = $height;
    $this->width  = $width;
 
    switch( $type ) {
        case "png":
            $this->mime = 'png';
            return header('Content-Type: image/png');
        break;
        case "gif":
            $this->mime = 'gif';
            return header('Content-Type: image/gif');
        break;
        case "jpeg":
            $this->mime = 'jpeg';
            return header('Content-Type: image/jpeg');
        break;
    }
}

..and this is what you could have:
PHP:
public function config($type, $height = 0, $width = 0) {
    $this->height = $height;
    $this->width  = $width;
   
    if (in_array(strtolower($type), array("png","gif","jpeg"))) {
        $this->mime = strtolower($type);
        return header('Content-type: image/' . strtolower($type));
    }
}

But yeah, pretty cool, nice work.
 

Jian

Resident Weeb
Contributor
Sep 2, 2011
687
437
I can't help but think your config function could've been simplified a lot more.

This is what you have:
PHP:
public function config($type, $height = "0", $width = "0") {
    $this->height = $height;
    $this->width  = $width;
 
    switch( $type ) {
        case "png":
            $this->mime = 'png';
            return header('Content-Type: image/png');
        break;
        case "gif":
            $this->mime = 'gif';
            return header('Content-Type: image/gif');
        break;
        case "jpeg":
            $this->mime = 'jpeg';
            return header('Content-Type: image/jpeg');
        break;
    }
}

..and this is what you could have:
PHP:
public function config($type, $height = 0, $width = 0) {
    $this->height = $height;
    $this->width  = $width;
 
    if (in_array(strtolower($type), array("png","gif","jpeg"))) {
        $this->mime = strtolower($type);
        return header('Content-type: image/' . strtolower($type));
    }
}

But yeah, pretty cool, nice work.

Thanks for the heads up! I'll give you credits when I update! :)
 

Jian

Resident Weeb
Contributor
Sep 2, 2011
687
437
No problem, also, switch statements have been proven to be slightly slower than if statements. :up:

I always thought it's the opposite, lol. Cos people complain if and else are messy and stuff if too many is tangled together.
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
I always thought it's the opposite, lol. Cos people complain if and else are messy and stuff if too many is tangled together.
Switch statements do look tidier and are somewhat easier to read, but it's usually only me who reads my code anyway so I'd rather go for efficiency than slight tidiness on my code. ;P
 

Jian

Resident Weeb
Contributor
Sep 2, 2011
687
437
Switch statements do look tidier and are somewhat easier to read, but it's usually only me who reads my code anyway so I'd rather go for efficiency than slight tidiness on my code. ;P

Good point. Another note added. ;)
 

Jian

Resident Weeb
Contributor
Sep 2, 2011
687
437
What is this actually?

PHPGD is a feature in PHP that allows the script to create images. It's very flexible on what it can do:

But it's complicated to use at the same time. That's where NekoGD come into place. NekoGD simplifies that feature and allows the developer to create images using PHP more easily and the codes much more readable/less messy.
 

Users who are viewing this thread

Top