01-28-10, 07:59 AM
Wannabe Coder
Join Date: Jun 2008
Posts: 122
Thanks: 2
Thanked 0 Times in 0 Posts
Dynamic Images
Hello, I was just wondering how I would go about making an image that updated with information ?
01-28-10, 08:07 AM
Community Leader
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
01-28-10, 08:19 AM
Wannabe Coder
Join Date: Jun 2008
Posts: 122
Thanks: 2
Thanked 0 Times in 0 Posts
Okay, that is kinda what i was looking for however, I was wanting a complex image, so my plan was to make it in photoshop then using css I would have styled it, and made areas for the text to go, is there anyway I can still do that ?
01-28-10, 08:57 AM
Wannabe Coder
Join Date: Jun 2008
Posts: 122
Thanks: 2
Thanked 0 Times in 0 Posts
To show what I mean, here is a xbox live gamercard from another website:
http://card.mygamercard.net/h2o/xEX3CUT1ONx.png
I want to make something similar to that, I already have the xbox live information, I'm just unsure on how to get it into image form like that one is, would the imagestring method work someway ?
01-28-10, 09:14 AM
Wannabe Coder
Join Date: Sep 2009
Location: Moline, IL
Posts: 100
Thanks: 2
Thanked 1 Time in 1 Post
You can still use the function Nico suggested.
You would load your base photoshop PNG using gd functions. f you are using a PNG and have transparency make sure you account for that. You are not going to be able to use CSS styles on the text in the image.
You want to make your string to appear on the background base image. If you are using a special font make sure you load it first. Call imagestring on your image resource object specifying the coordinates where you want your text to appear. Then save the resource to a new file.
01-28-10, 09:19 AM
Wannabe Coder
Join Date: Jun 2008
Posts: 122
Thanks: 2
Thanked 0 Times in 0 Posts
Okay, I've been messing around with the imagestring function, and I may be overlooking things, but it looks like I can only have one string of text per image, as in the sample I posted there is a lot of different strings used, along with images.
01-28-10, 11:04 AM
Community Leader
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
You can call imagestring() multiple times if you need more text. You just have to change the positions accordingly.
As for the images, take a look at:
PHP: imagecopymerge - Manual
01-28-10, 11:08 AM
Wannabe Coder
Join Date: Jun 2008
Posts: 122
Thanks: 2
Thanked 0 Times in 0 Posts
Okay thanks everyone, I'll have a go
01-28-10, 02:52 PM
-
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
You might want to check out
http://www.imagemagick.org
That's what this is using
.PNG .JPG .GIF Banner Builder
Source that calls ImageMagick:
PHP Code:
<?php
$iWidth = $iBannerWidth = 764 ;
if (isset( $_POST [ 'iHeight' ]) && ( $_POST [ 'iHeight' ]!= '' ))
{
$iHeight = $_POST [ 'iHeight' ];
if (! is_numeric ( $iHeight ) ||
( $iHeight < 50 ) || ( $iHeight > 400 ))
return_json ( 'Invalid height' );
}
else
{
$iHeight = 170 ;
if (isset( $_POST [ 'iWidth' ]) && ( $_POST [ 'iWidth' ]!= '' ))
{
$iBannerWidth = $_POST [ 'iWidth' ];
if (! is_numeric ( $iBannerWidth ) ||
( $iBannerWidth < 50 ) || ( $iBannerWidth > 1280 ))
return_json ( 'Invalid width' );
}
}
$i = 0 ;
foreach ( $_FILES as $k => $v )
if ( $v [ 'size' ]!= 0 )
$i ++;
if ( $i != 0 )
$iWidth =(int)( $iBannerWidth / $i );
else
return_json ( 'No files' );
` rm tmp/* `;
$sList = '' ;
$sStatus = '' ;
$escHeight = escapeshellarg ( 'x' . $iHeight );
$escWidth = escapeshellarg ( $iWidth . 'x' );
/*
if ($iHeight!=170)
$sScale=' -resize '.$escHeight;
else
$sScale=' -resize '.$escWidth;
*/
$sScale = ' -resize ' . $escHeight ;
$iMinHeight = 100000 ;
$iMinWidth = 100000 ;
if ( count ( $_FILES )> 0 )
foreach ( $_FILES as $k => $v )
{
if ( $v [ 'error' ]== 0 )
{
if ( strpos ( $v [ 'type' ], 'image' )=== false )
return_json ( $v [ 'name' ]. ' is not an image.' );
else
{
if ( $v [ 'size' ]> 100000 )
return_json ( $v [ 'name' ]. ' is too big, images must be less than 100K.' );
else
{
$esckpng = escapeshellarg ( 'tmp/' . $k . '.png' );
shell_exec ( 'convert -size 500x400 ' . escapeshellarg ( $v [ 'tmp_name' ])
. $sScale . ' -flatten ' . $esckpng );
$sList .= ' ' . $esckpng ;
}
}
}
else
if ( $v [ 'name' ]!= '' )
return_json ( $v [ 'name' ]. ' (image ' . substr ( $k , 1 ). ') did not upload. Check the file size.' );
}
else
return_json ( 'No images' );
if ( $sList != '' )
{
$sImage = 'tmp/' . time ();
shell_exec ( 'convert -comment "Generated by http://wirehopper.com/design/banner.php" '
. $sList . ' +append -unsharp 0x.2 '
. ' +flatten -quality 100 '
. $sImage . '.png' );
switch ( $_POST [ 'rbEffect' ])
{
case 'G' :
$sCmd = 'cp ' . $sImage . '.png ' . $sImage . '.flat.png' ;
` $sCmd `;
$iWidth = exec ( 'identify ' . $sImage . '.flat.png | sed "s/^.*PNG \([0-9]*\)x.*$/\1/"' );
$escDim = escapeshellcmd ( $iWidth . 'x' . $iHeight );
shell_exec ( 'convert -comment "Generated by http://wirehopper.com/design/banner.php"'
. ' -size ' . $escDim
. ' gradient:black-none -sigmoidal-contrast 6,50% -colorize 100% '
. $sImage . '.flat.png -compose add -composite '
. ' -quality 100 ' . $sImage . '.png' );
break;
case 'S' :
$sCmd = 'cp ' . $sImage . '.png ' . $sImage . '.flat.png' ;
` $sCmd `;
$iWidth = exec ( 'identify ' . $sImage . '.flat.png | sed "s/^.*PNG \([0-9]*\)x.*$/\1/"' );
$iHeight = exec ( 'identify ' . $sImage . '.flat.png | sed "s/^.*PNG [0-9]*x\([0-9]*\).*$/\1/"' );
$escDim = escapeshellcmd ( $iWidth . 'x' . $iHeight );
$iOffset =(int)( $iHeight / 3 );
$i3Offset =(int)( $iOffset / 3 );
$iOffset *= 2 ;
shell_exec ( 'convert -comment "Generated by http://wirehopper.com/design/banner.php"'
. ' ' . $sImage . '.flat.png '
. ' -fill "#ffffff44" -draw "rectangle 0,' . $iOffset . ' ' . $iWidth . ',' .( $iOffset + $i3Offset ). '"'
. ' -fill "#ffffff77" -draw "rectangle 0,' .( $iOffset + $i3Offset + 1 ). ' ' . $iWidth . ',' .( $iOffset +( 2 * $i3Offset )). '"'
. ' -fill "#ffffffaa" -draw "rectangle 0,' .( $iOffset +( 2 * $i3Offset )+ 1 ). ' ' . $iWidth . ',' . $iHeight . '"'
. ' +flatten ' . $sImage . '.png' );
}
switch ( $_POST [ 'cbEffect' ])
{
case 'R' :
$sBackground = $_POST [ 'sBackground' ];
$aMatches =array();
$iMatch = preg_match ( '/#[\da-fA-F]{6}/' , $sBackground , $aMatches );
if ( $aMatches [ 0 ]!== $sBackground )
return_json ( 'Bad background color' );
$iW =(int) exec ( 'identify ' . $sImage . '.png | sed "s/^.*PNG \([0-9]*\)x.*$/\1/"' );
$iH =(int) exec ( 'identify ' . $sImage . '.png | sed "s/^.*PNG [0-9]*x\([0-9]*\).*$/\1/"' );
$fRatio = max ((int)( max ( $iW , $iH )/ min ( $iW , $iH ))* 2 , 5 );
$iRW =(int)( $iW / $fRatio );
$iRH =(int)( $iH / $fRatio );
$iRMax = max ( $iRW , $iRH );
$iRMin = min ( $iRW , $iRH );
$iStroke =(int)( $iRMax / 2 );
$iArc =(int)( $iStroke / 2 )+ 1 ;
$iAnchor = $iRMax + 1 ;
$sSize = '-size ' . escapeshellarg ( $iW . 'x' . $iH );
$sTmp = $sImage . '.tmp.png' ;
$sCp = 'cp ' . $sImage . '.png ' . $sTmp ;
` $sCp `;
$sCmdSize = 'convert ' . $sSize ;
$sDraw = $sCmdSize . ' ' . $sTmp
. ' -stroke "' . $sBackground . '" -strokewidth ' . $iStroke . ' -fill "' . $sBackground . '"'
. ' -draw ' . escapeshellarg ( 'arc -' . $iArc . ',' . $iAnchor . ' ' . $iAnchor . ',-' . $iArc . ' 180,270' )
. ' -draw ' . escapeshellarg ( 'arc -' . $iArc . ',' .( $iH - $iAnchor ). ' ' . $iAnchor . ',' .( $iH + $iArc - 1 ). ' 90,180' )
. ' -draw ' . escapeshellarg ( 'arc ' .( $iW - $iAnchor - 1 ). ',' .( $iH - $iAnchor - 1 ). ' ' .( $iW + $iArc - 1 ). ',' .( $iH + $iArc - 1 ). ' 0,90' )
. ' -draw ' . escapeshellarg ( 'arc ' .( $iW - $iAnchor - 1 ). ',' . $iAnchor . ' ' .( $iW + $iArc - 1 ). ',-' . $iArc . ' 270,360' )
. ' -flatten -transparent "' . $sBackground . '"'
. ' -blur 0x0.1 -quality 100 ' . $sImage . '.png' ;
` $sDraw `;
}
shell_exec ( 'convert -comment "Generated by http://wirehopper.com/design/banner.php" ' . $sImage . '.png -flatten -quality 100 ' . $sImage . '.gif' );
shell_exec ( 'convert -comment "Generated by http://wirehopper.com/design/banner.php" ' . $sImage . '.png -flatten -quality 100 ' . $sImage . '.jpg' );
$iCount = file_get_contents ( 'banner.count.txt' );
file_put_contents ( 'banner.count.txt' , $iCount + 1 );
return_json ( 'Done' , $sImage );
}
else
return_json ( 'Error. Either no images were submitted, or the files were too large. Limit is 100K per image, 1M per submission.' );
function return_json ( $sStatus , $sImage = '../images/no.gif' )
{
$sStatus = addslashes ( $sStatus );
$sImage = urlencode ( $sImage );
echo<<<HTML
<html>
<head>
<script>isLoaded = true;</script>
</head>
<body>
<textarea>{'status':' $sStatus ','textdata':' $sImage '}</textarea>
</body>
</html>
HTML;
exit();
}
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off