GD Image Library Example

Original JPG image

Resized JPG by target size

Buttons Using GD Fonts:

Vertical Text Bars using TrueType Fonts:

Original GIF image

Resized GIF by scale

Resized GIF to target max dim while maintaining aspect ratio

Testing Color Conversion Functions

Background Color FF0000 hex goes to (255,0,0) in RGB

Text Color 006633 hex goes to (0,102,51) in RGB

Source

The source code for this example page is:


...and the source code for the script called tba_resize_image.php that resizes an image based on a scaling factor is:

<?php
header
("Content-type: image/jpeg"); 
Header("Content-type: image/png"); 

// we expect $scale and $image to be defined, having been passed to us via
// query string, e.g. http://www.foo.com/tba_resize_image.php?image=test.gif&scale=4 

// create an image object from the source file
$srcImg imagecreatefromgif($image);

// create a (blank) smaller image object
$srcSize getimagesize($image);
$dstImg imagecreate($srcSize[0]/$scale$srcSize[1]/$scale);


// You can set up your image to be automatically made at the proper aspect ratio using this code:

$width 200;
$height150;
$aspect_ratio = (imagesx($srcImg)/imagesy($srcImg));
if(
$aspect_ratio < ($width/$height))
{
$width $height*$aspect_ratio;
} elseif(
$aspect_ratio > ($width/$height)) {
$height $width/$aspect_ratio;
}

// copy and resize from the source image object to the smaller blank one
imagecopyresized($dstImg$srcImg0000,
                  
$srcSize[0]/$scale$srcSize[1]/$scale,
                  
$srcSize[0], $srcSize[1]);

// send the smaller image object to the browser
header("Content-Type: image/gif");
imagegif($dstImg);

// clean up
imagedestroy($scrImg);
imagedestroy($dstImg);

?>


...and the source code for the script called tba_resize_image.php that resizes an image based on a target size is:

does the work of generating a resized image is:

<?php
header
("Content-type: image/jpeg"); 
Header("Content-type: image/png"); 

// we expect $scale and $image to be defined, having been passed to us via
// query string, e.g. http://www.foo.com/tba_resize_image.php?image=test.gif&scale=4 

// create an image object from the source file
$srcImg imagecreatefromgif($image);

// create a (blank) smaller image object
$srcSize getimagesize($image);
$dstImg imagecreate($srcSize[0]/$scale$srcSize[1]/$scale);


// You can set up your image to be automatically made at the proper aspect ratio using this code:

$width 200;
$height150;
$aspect_ratio = (imagesx($srcImg)/imagesy($srcImg));
if(
$aspect_ratio < ($width/$height))
{
$width $height*$aspect_ratio;
} elseif(
$aspect_ratio > ($width/$height)) {
$height $width/$aspect_ratio;
}

// copy and resize from the source image object to the smaller blank one
imagecopyresized($dstImg$srcImg0000,
                  
$srcSize[0]/$scale$srcSize[1]/$scale,
                  
$srcSize[0], $srcSize[1]);

// send the smaller image object to the browser
header("Content-Type: image/gif");
imagegif($dstImg);

// clean up
imagedestroy($scrImg);
imagedestroy($dstImg);

?>

©2018 Taylor Anderson

The Good Stuff

Japan Stuff is here, though the content is still limited.

Barbershop Stuff contains links to great resources for four-part Barbershop-style harmony. Nothing at all to do with cutting hair...

Unigraphics NX Stuff will be here, though there's nothing there yet...

Web Design Stuff is here, though the content is still limited.

LDS Stuff is here. Articles and content regarding the Church of Jesus Christ of Latter-day Saints.

Fun Stuff is here. Humor and games -- stuff to make you laugh and/or burn inordinate amounts of time.

The FAQ is here. Organized questions, random questions, more coming later, of course...

Photo Gallery is here.

Why is Taylor always smiling?

GrandmaSusie.com Logo
He loves his family...

LDS Church Logo
He loves his faith...

Masters of Harmony Logo
He loves his music...

NX Logo
He loves his work...


He loves knowing smarter people...


fun red X animation