# PHP Image Colours?

**URL:** <https://forum.kirupa.com/t/php-image-colours/229462>\
**Category:** programming\
**Created:** [June 17, 2007, 5:40pm UTC](https://forum.kirupa.com/t/php-image-colours/229462 "2007-06-17T17:40:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![duncanhall](https://avatars.discourse-cdn.com/v4/letter/d/ad7895/32.png) [@duncanhall](https://forum.kirupa.com/u/duncanhall)\
**Post date:** [June 17, 2007, 5:40pm UTC](https://forum.kirupa.com/t/php-image-colours/229462/1 "2007-06-17T17:40:13Z")

</div>

I’m dynaically creating images using \*imagecreatetruecolor(), \*and I’m purposefully leaving the bottom half of the created image blank because it’s going to be the rollover state of the image.

How can you specify the backround colour of an image created using \*imagecreatetruecolor()?

\*This is my function so far:

```php

function create_thumb($name,$filename,$new_w,$new_h){

    $src_img = imagecreatefromjpeg($name);
    $original_x = imagesx($src_img);
    $original_y = imagesy($src_img);    

    $dst_img = imagecreatetruecolor($new_w,$new_h*2);
    
    imagecolorset($dst_img, 0, 255, 0, 0);
    
    $half_x = $original_x / 2;
    $half_y = $original_y / 2;
    
    $min_x = $half_x - ($half_x/2);
    $max_x = $half_x + ($half_x/2);
    
    $min_y = $half_y - ($half_y/2);
    $max_y = $half_y + ($half_y/2);
    
    $start_x = rand($min_x, $max_x);
    $start_y = rand($min_y, $max_y);
    
    imagecopyresampled($dst_img, $src_img, 0, 0, $start_x, $start_y, $new_w, $new_h, $new_w, $new_h); 
    imagejpeg($dst_img, $filename); 

    imagedestroy($dst_img); 
    imagedestroy($src_img); 
    
}

create_thumb("ayako_tanaka-8.jpg", "course-thumbs/ayako_tanaka_cover.jpg", 98, 73);

```
