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:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN" "http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>

<head>
<TITLE>TBA Image Testing</TITLE>
<LINK REL=StyleSheet HREF="../decor/three_column_center_fluid.css" TYPE="text/css" >
</head>

<body>

<div id="banner">

    <?php include "../menus/bannertext.inc"?>

</div>

<div id="centercontent">


    <h2>GD Image Library Example</h2>

    <h3>Original JPG image</h3>
    <p><img src="trying.jpg" alt="" border="0"></p>

    <h3>Resized JPG by target size</h3>
    <p><img src="tba_resize_jpg_target.php?image=trying.jpg&amp;size=150" alt="" border="0"></p>

    <p>Buttons Using GD Fonts: <img src="button.php?text=testing 1&size=3"> <img src="button.php?text=Testing 2&size=3"> <img src="button.php?text=Testing 3&size=3"></p> 

    <p>Vertical Text Bars using TrueType Fonts: 
            <img src="vertical_text.php?text=Heralds of Harmony&bkg_color=0000FF&txt_color=FFFFFF"> 
            <img src="vertical_text.php?text=Who We Are&bkg_color=000000&txt_color=FFFFFF">
            <img src="vertical_text.php?text=Chapter Leadership&bkg_color=006600&txt_color=FFFFFF">
            <img src="vertical_text.php?text=Something Else&bkg_color=FF0000&txt_color=FFFFFF">
    </p> 

    <h3>Original GIF image</h3>
    <p><img src="test.gif" alt="" border="0"></p>

    <h3>Resized GIF by scale</h3>
    <p><img src="tba_resize_image.php?image=test.gif&amp;scale=4" alt="" border="0"></p>

    <h3>Resized GIF to target max dim while maintaining aspect ratio</h3>
    <p><img src="tba_resize_aspect.php?image=test.gif&amp;size=100" alt="" border="0"></p>

    <?php

    
function GiveDec($Hex)
    {
        if(
$Hex == "A"$Value 10;
        else if(
$Hex == "B"$Value 11;
        else if(
$Hex == "C"$Value 12;
        else if(
$Hex == "D"$Value 13;
        else if(
$Hex == "E"$Value 14;
        else if(
$Hex == "F"$Value 15;
        else 
$Value $Hex;
        return 
$Value;
    }

    function 
HexToDec($hex_value)
    {
        
$input strtoupper($hex_value);

        
$a GiveDec(substr($input01));
        
$b GiveDec(substr($input11));
        
$c GiveDec(substr($input21));
        
$d GiveDec(substr($input31));
        
$e GiveDec(substr($input41));
        
$f GiveDec(substr($input51));

        
$color[r] = ($a 16) + $b;
        
$color[g] = ($c 16) + $d;
        
$color[b] = ($e 16) + $f;

        return 
$color;
    }

    
$bgd_color_hex 'FF0000';
    
$txt_color_hex '006633';

    
$bgd_color_RGB HexToDec($bgd_color_hex);
    
$txt_color_RGB HexToDec($txt_color_hex);

    print 
"<h3>Testing Color Conversion Functions</h3>";
    
$format "<p>Background Color %s hex goes to (%d,%d,%d) in RGB<br><p>";
    
printf($format,$bgd_color_hex,$bgd_color_RGB[r],$bgd_color_RGB[g],$bgd_color_RGB[b]);
    
$format "<p>Text Color %s hex goes to (%d,%d,%d) in RGB<br><p>";
    
printf($format,$txt_color_hex,$txt_color_RGB[r],$txt_color_RGB[g],$txt_color_RGB[b]);
    
?>


    <h3>Source</h3>
    <p>The source code for this example page is:</p>
    <p><?php show_source($DOCUMENT_ROOT"/".$PHP_SELF); ?></p>

    <hr>
    <p>...and the source code for the script called tba_resize_image.php that resizes an image based on a scaling factor is:</p>
    <p><?php show_source("tba_resize_image.php"); ?></p>

    <hr>
    <p>...and the source code for the script called tba_resize_image.php that resizes an image based on a target size is:</p>
    does the work of generating a resized image is:</p>
    <p><?php show_source("tba_resize_image.php"); ?></p>

</div>




<div id="leftcontent">

    <?php include "../menus/leftmenu.inc"?>
    
</div>






<div id="rightcontent">

    <?php include "../menus/rightmenu.inc"?>
    
    <hr width=90%>

    <center><IMG SRC="../web_design/redx016.gif" ALT="fun red X animation" BORDER=0><br><br></center>

</div>

    <br style="clear:both;" />

</body>
</html>


...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);

?>

©2010 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