Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 a handy dandy image resizing function
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
PaddyLong




PostPosted: Thu Jul 24, 2003 11:04 am   Post subject: a handy dandy image resizing function

here's an image resizing function that I wrote for one of my projects... it may be helpful for you too

all it does is make it so the width and height remain in proportion

code:

//this function is used to resize and display images
/*
imagefile - the file name of the image
alt - the tooltip text that appears when you hover over the image
limiter - which value you want to limit - 0 for width, 1 for height
limitervalue - the maximum value that the limiter value can be
isthumbnail - whether or not to make the image into a thumbnail (if yes, then acts as link to itself) - 0 for no, 1 for yes
caption - caption you want to appear under the text ("" for no caption)
align - the div class to use ("" for no div tag)
class - the class you would like the image to be ("" for none)

styles that should be in the page's stylesheet...
imageLink (needed if the isthumbnail parameter is 1) - recomended property - background-color: transparent;
caption (needed if the caption parameter is set)
*/

function resizeimage ($imagefile, $alt, $limiter, $limitervalue, $isthumbnail, $caption, $align, $class){
        $picsize=getimagesize($imagefile);
        if($picsize[$limiter]>$limitervalue){
                $timestoobig=$picsize[$limiter]/$limitervalue;
                $picwidth=floor($picsize[0]/$timestoobig);
                $picheight=floor($picsize[1]/$timestoobig);
        }else{
                $picwidth=$picsize[0];
                $picheight=$picsize[1];
        }
        $outString = "";
        if($align != ""){ $outString .= "<div class=\"".$align."\">"; }
        if($isthumbnail==1){ $outString .= "<a href=\"".$imagefile."\" target=\"_blank\" class=\"imageLink\">"; }
        $outString .= "<img src=\"".$imagefile."\" alt=\"".$alt."\" width=\"".$picwidth."\" height=\"".$picheight."\"";
        if($class != ""){ $outString .= " class=\"".$class."\""; }
        $outString .= " />";
        if($caption != ""){ $outString .= "<br /><span class=\"caption\">".$caption."</span>"; }
        if($isthumbnail==1){ $outString .= "</a>"; }
        if($align != ""){ $outString .= "</div>\n"; }
        print($outString);
}


edit: made code more universal
Sponsor
Sponsor
Sponsor
sponsor
Amailer




PostPosted: Thu Jul 24, 2003 11:58 am   Post subject: (No subject)

hehe nice,
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: