|
|
|
|
![]() ![]() |
May 25 2008, 06:11 PM
Post
#1
|
|
|
Member [ Level 1 ] Group: [HOSTED] Posts: 36 Joined: 28-August 07 Member No.: 24,433 |
Im working on a dynamic image, can i put 2 images in same dynamic image, and can i make this code shorter?
CODE if ( $goal == 31 ) {
$xp2 = ('14833'); } elseif ( $goal == 32 ) { $xp2 = ('16456'); } elseif ( $goal == 33 ) { $xp2 = ('18247'); } elseif ( $goal == 34 ) { $xp2 = ('20224'); } elseif ( $goal == 35 ) { $xp2 = ('22406'); } elseif ( $goal == 36 ) { $xp2 = ('24815'); } elseif ( $goal == 37 ) { $xp2 = ('27473'); } elseif ( $goal == 38 ) { $xp2 = ('30408'); } elseif ( $goal == 39 ) { $xp2 = ('33648'); } elseif ( $goal == 40 ) { $xp2 = ('37224'); } elseif ( $goal == 41 ) { $xp2 = ('41171'); } elseif ( $goal == 42 ) { $xp2 = ('45529'); } elseif ( $goal == 43 ) { $xp2 = ('50339'); } elseif ( $goal == 44 ) { $xp2 = ('55649'); } elseif ( $goal == 45 ) { $xp2 = ('61512'); } elseif ( $goal == 46 ) { $xp2 = ('67983'); } elseif ( $goal == 47 ) { $xp2 = ('75127'); } elseif ( $goal == 48 ) { $xp2 = ('83014'); } elseif ( $goal == 49 ) { $xp2 = ('91721'); } elseif ( $goal == 50 ) { $xp2 = ('101333'); } elseif ( $goal == 51 ) { $xp2 = ('111945'); } elseif ( $goal == 52 ) { $xp2 = ('123660'); } elseif ( $goal == 53 ) { $xp2 = ('136594'); } elseif ( $goal == 54 ) { $xp2 = ('150872'); } elseif ( $goal == 55 ) { $xp2 = ('166636'); } elseif ( $goal == 56 ) { $xp2 = ('184040'); } elseif ( $goal == 57 ) { $xp2 = ('203254'); } elseif ( $goal == 58 ) { $xp2 = ('224466'); } elseif ( $goal == 59 ) { $xp2 = ('247886'); } elseif ( $goal == 60 ) { $xp2 = ('273742'); } elseif ( $goal == 61 ) { $xp2 = ('302288'); } elseif ( $goal == 62 ) { $xp2 = ('333804'); } elseif ( $goal == 63 ) { $xp2 = ('368599'); } elseif ( $goal == 64 ) { $xp2 = ('407015'); } elseif ( $goal == 65 ) { $xp2 = ('449428'); } elseif ( $goal == 66 ) { $xp2 = ('496254'); } elseif ( $goal == 67 ) { $xp2 = ('547953'); } elseif ( $goal == 68 ) { $xp2 = ('605032'); } elseif ( $goal == 69 ) { $xp2 = ('668051'); } elseif ( $goal == 70 ) { $xp2 = ('737627'); } elseif ( $goal == 71 ) { $xp2 = ('814445'); } elseif ( $goal == 72 ) { $xp2 = ('899257'); } elseif ( $goal == 73 ) { $xp2 = ('992895'); } elseif ( $goal == 74 ) { $xp2 = ('1096278'); } elseif ( $goal == 75 ) { $xp2 = ('1210421'); } elseif ( $goal == 76 ) { $xp2 = ('1336443'); } elseif ( $goal == 77 ) { $xp2 = ('1475581'); } elseif ( $goal == 78 ) { $xp2 = ('1629200'); } elseif ( $goal == 79 ) { $xp2 = ('1798808'); } elseif ( $goal == 80 ) { $xp2 = ('1986068'); } elseif ( $goal == 81 ) { $xp2 = ('2192818'); } elseif ( $goal == 82 ) { $xp2 = ('2421087'); } elseif ( $goal == 83 ) { $xp2 = ('2673114'); } elseif ( $goal == 84 ) { $xp2 = ('2951373'); } elseif ( $goal == 85 ) { $xp2 = ('3258594'); } elseif ( $goal == 86 ) { $xp2 = ('3597792'); } elseif ( $goal == 87 ) { $xp2 = ('3972294'); } elseif ( $goal == 88 ) { $xp2 = ('4385776'); } elseif ( $goal == 89 ) { $xp2 = ('4842295'); } elseif ( $goal == 90 ) { $xp2 = ('5346332'); } elseif ( $goal == 91 ) { $xp2 = ('5902831'); } elseif ( $goal == 92 ) { $xp2 = ('6517253'); } elseif ( $goal == 93 ) { $xp2 = ('7195629'); } elseif ( $goal == 94 ) { $xp2 = ('7944614'); } elseif ( $goal == 95 ) { $xp2 = ('8771558'); } elseif ( $goal == 96 ) { $xp2 = ('9684577'); } elseif ( $goal == 97 ) { $xp2 = ('10692629'); } elseif ( $goal == 98 ) { $xp2 = ('11805606'); } elseif ( $goal == 99 ) { $xp2 = ('13034431'); } else { $xp2 = ('0'); } |
|
|
|
May 26 2008, 04:18 AM
Post
#2
|
|
|
Absolute Newbie Group: Admin Posts: 888 Joined: 20-February 05 From: Indianapolis, Indiana, USA (Midwest) Member No.: 2,714 |
Yes, you can have multiple images in your dynamic image. It has been a while since I've done dynamic images so I won't try to code it for you today but I'll explain how it normally works.
You normally start your dynamic image script by loading a background image or setting a blank or solid colored image with imagecreate() or similar function. You then add an image over the top of that image with imagecopy() or similar function. You can then use image copy again and again and it will insert the part of the image to use into your new image where you specify. Each new image inserted will be layered on top of what ever already exists in the dynamic image. So you can imagecopy() a a button or some other image segment then do another imagecopy() to place a border around that etc... Now, for your second question... You could use a switch! CODE switch ($goal) { case 31: $xp2 = ('14833'); break; case 32: $xp2 = ('16456'); break; case 33: $xp2 = ('18247'); break; // etc... } Not particularly better... I would use an array. CODE $xp_array = array(14833, 16456, 18247, 20224, 22406); // etc... $xp2 = $xp_array[$goal - 31]; In this case, $xp_array[0] = 14833; So to get to get the zero index, we have to subtract 31 from $goal right! As a result, $xp_array[1] = 16456; Because 32 - 31 = 1 I hope you understand how this works. The array index starts at zero but your scale starts at 31. To get your scale to match the array index, you have to subtract 31. As a result, the following is true: 0 = 31 = 14833 1 = 32 = 16456 2 = 33 = 18247 3 = 34 = 20224 4 = 35 = 22406 You may then want to have a check to see if the value of $goal is below 31 or above 99 and act accordingly. Good luck vujsa |
|
|
|
May 26 2008, 04:11 PM
Post
#3
|
|
|
Member [ Level 1 ] Group: [HOSTED] Posts: 36 Joined: 28-August 07 Member No.: 24,433 |
Thanks very much, its works good and it faster now
CODE $xp_array = array(14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953, 605032, 668051, 737627, 899257, 814445, 899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577, 10692629, 13034431); $xp2 = $xp_array[$goal - 31]; I gonna try imagecopy(). |
|
|
|
May 26 2008, 08:45 PM
Post
#4
|
|
|
Absolute Newbie Group: Admin Posts: 888 Joined: 20-February 05 From: Indianapolis, Indiana, USA (Midwest) Member No.: 2,714 |
Thanks very much, its works good and it faster now CODE $xp_array = array(14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408, 33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127, 83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636, 184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599, 407015, 449428, 496254, 547953, 605032, 668051, 737627, 899257, 814445, 899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200, 1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594, 3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253, 7195629, 7944614, 8771558, 9684577, 10692629, 13034431); $xp2 = $xp_array[$goal - 31]; I gonna try imagecopy(). I'm glad that I could help. Yeah, the script should run much faster now. It is amazing how much easier and quicker a script can run just by changing the code a little bit. Before, the server had to check 68 conditional statements (if, else if, else) but now it only looks for one specific item in an array. If I had quickly found a pattern to the $xp2 values, it would be even quicker to do it all mathematically. Something like this: CODE $xp2 = $goal - 31 + 14833 + (($goal - 31) * .01); This of course isn't the correct formula but if you had a formula to use instead of an array, you would save even more lines of code and speed up the script. Good luck, vujsa |
|
|
|
May 28 2008, 04:57 PM
Post
#5
|
|
|
Member [ Level 1 ] Group: [HOSTED] Posts: 36 Joined: 28-August 07 Member No.: 24,433 |
I got a small problem, when It load the background on the dynamic image, if the image file dont exist it say error in the image, do u remember or know how to fix it? I use
CODE $im = imagecreatefrompng("$string.png"); edit: If a varible is more then 100, can i do so it change to 100? This post has been edited by Normano: May 28 2008, 06:43 PM |
|
|
|
May 29 2008, 04:48 AM
Post
#6
|
|
|
Absolute Newbie Group: Admin Posts: 888 Joined: 20-February 05 From: Indianapolis, Indiana, USA (Midwest) Member No.: 2,714 |
I got a small problem, when It load the background on the dynamic image, if the image file dont exist it say error in the image, do u remember or know how to fix it? I use CODE $im = imagecreatefrompng("$string.png"); edit: If a varible is more then 100, can i do so it change to 100? No problem, just check for the image first... CODE if (file_exists($string.png)) { $im = imagecreatefrompng("$string.png"); } This way the image copy is only attempted if the image exists. As for your 100 question, I assume you mean if $goal for some reason is larger than 99... Let's say that a $goal of 99 is the maximum so if a number is larger than that, it should be reset to 99 and maybe 31 is the minimum so reset $goal below that to 31 like so: CODE if($goal > 99){ $goal = 99; } else if ($goal < 31){ $goal = 31; } $xp_array = array(14833, 16456, 18247, 20224, 22406); // etc... $xp2 = $xp_array[$goal - 31]; I hope this answers your questions. vujsa |
|
|
|
May 30 2008, 03:35 PM
Post
#7
|
|
|
Member [ Level 1 ] Group: [HOSTED] Posts: 36 Joined: 28-August 07 Member No.: 24,433 |
Thanks very much:)
|
|
|
|
Jun 1 2008, 12:25 PM
Post
#8
|
|
|
Absolute Newbie Group: Admin Posts: 888 Joined: 20-February 05 From: Indianapolis, Indiana, USA (Midwest) Member No.: 2,714 |
|
|
|
|
Jun 1 2008, 07:21 PM
Post
#9
|
|
|
Member [ Level 1 ] Group: [HOSTED] Posts: 36 Joined: 28-August 07 Member No.: 24,433 |
CODE if($goal < $lvl){ this script do so if $lvl is bigger then $goal it say "Goal Reached, Congrats!" but if $goal and $lvl is same how do i code so it say "Goal Reached, Congrats!"? thanks for all help imagestring($im, 2, 150, 14, "Goal Reached, Congrats!", $black); imagestring($im, 2, 149, 13, "Goal Reached, Congrats!", $white); }else{ imagestring($im, 2, 150, 14, "XP Left: $xp_left", $black); imagestring($im, 2, 149, 13, "XP Left: $xp_left", $white); } This post has been edited by Normano: Jun 1 2008, 07:21 PM |
|
|
|
Jun 1 2008, 08:20 PM
Post
#10
|
|
|
Absolute Newbie Group: Admin Posts: 888 Joined: 20-February 05 From: Indianapolis, Indiana, USA (Midwest) Member No.: 2,714 |
CODE if($goal < $lvl){ this script do so if $lvl is bigger then $goal it say "Goal Reached, Congrats!" but if $goal and $lvl is same how do i code so it say "Goal Reached, Congrats!"? thanks for all help imagestring($im, 2, 150, 14, "Goal Reached, Congrats!", $black); imagestring($im, 2, 149, 13, "Goal Reached, Congrats!", $white); }else{ imagestring($im, 2, 150, 14, "XP Left: $xp_left", $black); imagestring($im, 2, 149, 13, "XP Left: $xp_left", $white); } Well, you would use "less than or equal to" instead of "less than". Here is your modified code: CODE if($goal <= $lvl){ imagestring($im, 2, 150, 14, "Goal Reached, Congrats!", $black); imagestring($im, 2, 149, 13, "Goal Reached, Congrats!", $white); }else{ imagestring($im, 2, 150, 14, "XP Left: $xp_left", $black); imagestring($im, 2, 149, 13, "XP Left: $xp_left", $white); } Here is some more information about comparison operators. http://us2.php.net/manual/en/language.oper....comparison.php Hope this helps, vujsa |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 16th October 2008 - 08:16 PM |