*Author

ftbhrygvn

  • Guest
Re: Elements deck image generator https://elementscommunity.org/forum/index.php?topic=4173.msg42821#msg42821
« Reply #36 on: March 23, 2010, 03:39:37 pm »
 
Still missing the Relic pictures for unupgraded and upgraded, and the upgraded marks card pictures. I you have one of these and could take a screenshot of it, in a lossless format like PNG, I could add better pictures for them.
I'm fighting Dark Matter in hope to get a relic. I'll post it for you if I am successful

Scaredgirl

  • Guest
Re: Elements deck image generator https://elementscommunity.org/forum/index.php?topic=4173.msg42825#msg42825
« Reply #37 on: March 23, 2010, 03:57:27 pm »
I think having a
Hover over cards for details, click for permalink
Deck import code : [Select]
could much more efficient and convenient for everybody. Plus, I don't have a server ;)

I could give you my script, or if you wish I could look how I could implement it (Delreich gave me a starting directions).
The script could be improved I think too, performance wise. It's really naive in it's current form. And some piece of code are useless if used with BBCodes.
PM me if you think it's more convenient ;)
If you would like to look at how your code could be implemented in our forum forum software, that would be great.

We use SMF 2.0 RC2 forum software.

The way I see it, we have 2 options:

Option 1 - BBcode
Here's an example countdown BBcode modification we use on this forum: http://custom.simplemachines.org/mods/index.php?mod=1952

If you choose SMF 2.0 RC2 from the drop-down menu on the right and click "Parse", you will see all the code changes needed to make the thing work.

You can see the countdown button in the post writing window and it generates:
Code: [Select]
[countdown][/countdown]That particular modification is really simple and I'm not 100% sure if you can use the same method to implement your code but I would imagine the basics like button creating are the same.

I'm not sure what kind of information or files you need to make the code work. Just ask me anything and I'll try to deliver.


Option 2 - Advanced
We could have some kind of advanced system like a separate text box for deck code or maybe something like the "Add image(s) to post" button down there.

This would of course require much more work so I think BBcode is the best way to go.


Working out nice, planplan. Nice work.
Seems that my hosting is updating their server. I am now using a hosting that I seldom use:
http://ftbhrygvn.ueuo.com/
The files are still uploading. Should be done in an hour's time

Some comments:
Your deck image generator (generator for short) always outputs jpeg. Add and option to change the output format.
Nice ordering feature.
Not tested properly, but seems that your generator is slower than mine
Need more accessible interface
You can of course do your own version of what planplan did but if you really want to help, I would recommend you use your time to code something else. I mean we don't really need two almost identical systems, now do we?

I'm sure there are other similar projects as well that would be a great challenge to you coding wizards.

ftbhrygvn

  • Guest
Re: Elements deck image generator https://elementscommunity.org/forum/index.php?topic=4173.msg42828#msg42828
« Reply #38 on: March 23, 2010, 04:07:50 pm »
Just tested speed.

Tested with 60-QP deck with Aether mark
All times in seconds

Mine:
from paste code to submit: 1.0
from paste code to finish: 5.1

Yours:
from paste code to submit: 2.3
from paste code to finish: 22.9

You really need a more accessible interface and improvement in algorithm.
BTW, my image is 73.67KB, yours is 106.92KB


ninja'd by SG:
Just give you another option and I feel more comfortable to use something I created myself.

By the comparision and results I have posted, I can conclude that my generator is better in terms of accessibilty, time, format option and image size. Also, my generator generates and error when an invalid code is encountered instead of putting a ? card in the place. Planplan has better shadows and the ordering features, but I'm working on these also.

Just in case if you get confused, I started working on this before planplan has posted this topic

ftbhrygvn

  • Guest
Re: Elements deck image generator https://elementscommunity.org/forum/index.php?topic=4173.msg42840#msg42840
« Reply #39 on: March 23, 2010, 04:33:01 pm »
Just restarted my router and the trasfer speed increased dramatically. Currently at 90 files/min

EDIT: I was doing 100< for 30 mins and completed the rest >250 in 5 mins after this post...... Don't underestimate the awesomeness of router restart

Delreich

  • Guest
Re: Elements deck image generator https://elementscommunity.org/forum/index.php?topic=4173.msg42845#msg42845
« Reply #40 on: March 23, 2010, 04:43:02 pm »
Can't really test speed in any sensible way when the scripts are hosted on different servers in different parts of the world...
For me they're about even.

Relics:

I'll leave the fine cropping to you. Full images can be found in the Relic (http://elementscommunity.org/forum/index.php/topic,2443.0.html) thread.

ftbhrygvn

  • Guest
Re: Elements deck image generator https://elementscommunity.org/forum/index.php?topic=4173.msg42858#msg42858
« Reply #41 on: March 23, 2010, 05:23:07 pm »
Oh, I missed that part.
I pinged both servers and planplan's server is 37% slower, but the generate times is 3 times slower

Thanks for the Relic. IMAGE DB COMPLETED (robotic sound)

EDIT:
Oh, BTW, seems that ueuo is giving me 1000TB bandwidth for free!!

Offline PlanplanTopic starter

  • Jr. Member
  • **
  • Posts: 130
  • Country: fr
  • Reputation Power: 8
  • Planplan is a Spark waiting for a buff.
Re: Elements deck image generator https://elementscommunity.org/forum/index.php?topic=4173.msg42871#msg42871
« Reply #42 on: March 23, 2010, 05:42:57 pm »
Thanks Delreich for the two pictures. They are now uploaded.

I have a working [ deck=mark](...)[ /deck] script now. I'm adding some security measures and I'll send you the piece of code Scaredgirl.

My server is my ISP personnal pages, slow ping and slow script execution. But maybe my script could be improved. I already know the struggle point, and how to minimize them, at the cost of maintenance issues (switching the pictures in the GD format for example). Also, I could make my script quicker at the cost of more server RAM by keeping image in memory until end of script. Speed isn't everything.

I'm also compressing the url with a custom function... So a decompression is also done behind.

Also, I'm generating a JPEG with a 95% quality. Your's is standard (and lower) quality. Thus the size difference.

That's all for the explications... I don't want to start a "code challenge". I'm just trying to give the best solution I can do. I think you can't compare two script until you know what's behind. If it could be improved, I'll gladely hear, I don't know everything :P

ftbhrygvn

  • Guest
Re: Elements deck image generator https://elementscommunity.org/forum/index.php?topic=4173.msg43248#msg43248
« Reply #43 on: March 24, 2010, 02:51:52 pm »
I don't want to start a "code challenge" neither, and I am NOT. I'm just saying your generator can be improved, for the forum users' sake. Don't think I came across this post by accident and "Oh! I can do better" then made this just to beat you. I had the idea, but no passion. When I want to make a deck, I saw this post, and I was motivated. I should thank you if you think it that way.

And yes, I admit. I don't have url compression, but that can be done in a few lines.

The image you generate is JPEG (95% as you have said), but as I'm generating PNG, the quality should be better, at least not worse.

If you would like to improve, I can help you. As I have said, I'm not trying to beat you.

Let me explain how my generator (http://ftbhrygvn.ueuo.com/) works.
Two pages: index.html, generate.php
index.html is just HTML, you can see the source code.
generate.php is just contains 21 lines, with the PHP tags on seperate lines, and 1 line is just a close bracket, so it's 18 if you don't count these.
If you are still reading, then this (YES! I'M PUBLICIZING MY CODE):
Code: [Select]
<?php
$im 
imagecreatefrompng('images/board.png');
if(
$_GET['cards']=='') die('Invalid deck');
$l implode('',explode(' ',$_GET['cards']));
$l str_split($l,3);
if(
sizeof($l)>60) die('Invalid deck');
for(
$i 0$i sizeof($l); $i++){
$c = @imagecreatefrompng('images/'.$l[$i].'.png') or die('Invalid card code for card no. '.$i.': '.$l[$i]);
$s = @imagecreatefrompng('images/shadow.png') or die('Can\'t open image');
$x 15+floor($i/10)*88.9;
$y 5+($i-floor($i/10)*10)*18.5;
imagecopy($im,$c,$x,$y,0,0,73,73);
imagecopy($im,$s,$x-3,$y-2,0,0,79,75);
}
$c = @imagecreatefrompng('images/marks/'.$_GET['mark'].'.png') or die('Invalid mark');
imagecopy($im,$c,565,6,0,0,73,73);
if(
$_GET['format']==''$_GET['format'] = 'png'
header('Content-Type: image/'.$_GET['format']);
eval(
'image'.$_GET['format'].'($im);');
imagedestroy($im);
?>

See  how I have done much more with just 21 (or 18) lines. And I admit, I don't have url compression and ordering. But I'm working on those. maybe you can send me your code and let me see how we can improve it. (Seems that you are using many lines of codes as you have said "security measures")

EDIT: Forgot to mention the interface. Using a drop menu is not a good choice in terms of accessibility. Something like mine allows the user to select the Mark easily.

Oh, and if you want to see my progress, go to http://ftbhrygvn.selfip.com/elements/generator/
WARNING: TERRIBLE UPTIME OF <30%

ftbhrygvn

  • Guest
Re: Elements deck image generator https://elementscommunity.org/forum/index.php?topic=4173.msg43294#msg43294
« Reply #44 on: March 24, 2010, 05:58:49 pm »
Just updated my generator, now it consist of 3 files:
index.html: only changed request target of the form
simp.php: NEW, responsible for formatting inputs, including ordering
generate.php: still the generator body, takes formatted input from simp.php and generate image

Now, generate.php takes only 1 GET parameter, which contains all information it needs to generate the image.
The parameter pattern: <mark>(<5-character codes>)<format>
<mark> is the full name of the mark. Eg. darkness
<5-character code> consists of a 2-digit number and a 3-character card code, the number is the number of that card. Eg. 164sa, meaning 16 QPs
<format> is png, jpeg, or gif. If this is omitted, png is assumed.

For example: darkness034sa014t3125uk015ul045um035un015uo035up015uq035us0461o0161p0161q0161r0161spng generates png for the starter deck of Darkness

Hope I explained it clearly

simp.php
Code: [Select]
<?php
$s 
$_GET['mark'];
$l str_split(implode('',explode(' ',$_GET['cards'])),3);
if(
sizeof($l)>60header('Location: generate.php?d=Invalid+deck');
sort($l,SORT_STRING);
foreach(
array_count_values($l) as $k => $v$s .= str_pad($v,2,'0',STR_PAD_LEFT).$k;
$s .= $_GET['format'];
header('Location: generate.php?arg='.$s);
?>
generate.php
Code: [Select]
<?php
if(array_key_exists('d',$_GET)) die($_GET['d']);
preg_match('/^([^\d]+)(.+)/',$_GET['arg'],$m);
$im imagecreatefrompng('images/board.png');
$l str_split($m[2],5);
$u 0;
for(
$i 0$i sizeof($l)-1$i++){
for($j 0$t intval(substr($l[$i],0,2)); $j $t$j++, $u++){
$c = @imagecreatefrompng('images/'.substr($l[$i],2).'.png') or die('Invalid card code: '.substr($l[$i],2));
$s = @imagecreatefrompng('images/shadow.png') or die('Can\'t open image');
$x 15+floor($u/10)*88.9;
$y 5+($u-floor($u/10)*10)*18.5;
imagecopy($im,$c,$x,$y,0,0,73,73);
imagecopy($im,$s,$x-3,$y-2,0,0,79,75);
}
}
$c = @imagecreatefrompng('images/marks/'.$m[1].'.png') or die('Invalid mark');
imagecopy($im,$c,565,6,0,0,73,73);
header('Content-Type: image/'.$l[sizeof($l)-1]);
eval(
'image'.$l[sizeof($l)-1].'($im);');
imagedestroy($im);
?>

Offline PlanplanTopic starter

  • Jr. Member
  • **
  • Posts: 130
  • Country: fr
  • Reputation Power: 8
  • Planplan is a Spark waiting for a buff.
Re: Elements deck image generator https://elementscommunity.org/forum/index.php?topic=4173.msg49283#msg49283
« Reply #45 on: April 06, 2010, 06:07:15 pm »
Some people asked me how I'm compressing the URL. Like I said, I only made a very naive script, here it is :
Code: [Select]
<?php

function compress_deck($deck_array)
{
    
$deck_string_compressed '';
    
$duplicate 1;
    for(
$i 0; isset($deck_array[$i]); ++$i)
    {
        if(
$deck_array[$i] == $deck_array[$i 1] && $duplicate 9)
            ++
$duplicate;
        elseif(
$duplicate 1)
        {
            
$deck_string_compressed .= 'z'.$duplicate.$deck_array[$i];
            
$duplicate 1;
        }
        else
            
$deck_string_compressed .= $deck_array[$i];
    }
    return 
$deck_string_compressed;
}

?>
Basically, I'm checking if you have more than one time the same card. If you have just one time the card, I'm just adding the card code to the string. If I have more than 1, I'm counting the total and add the key char "z", followed by the number of cards, then the card code. For example, 1 Quantum Pillar will be "4sa", and 5 are "z54sa". But this approach limit me to 9. Like I said, it's just a naive quick compression. And, I'm not using it anymore for the next forum ipdate I'm working on, caching instead.

ftbhrygvn approach is better for small decks with a lot of repeating cards. 30 cards mono and duo decks for example. For a typical deck of 12 pillars + 3 other cards 6 times, you will have a 20 char string. With my algo, you'll have a 25 chars string.
But in the worst case, 60 different cards, ftbhrygvn algo will generate a 5 * 60 char string, against 3*60 for mine. Different approach, different results in different cases.

For my generating code, as ftbhrygvn seems to want to help me improve it and discuss it in the topic he made, here what I have for the moment. Pretty close to your code.
I have a big switch only because this version is for the forum, and I have to adapt it for BBCodes. I also have a string cleaning function before this function.
Also, the shadow is applied to the base images to gain a bit of speed and memory.
Code: [Select]
<?php

$deck_array 
preg_split('/\s/'$deck_stringNULLPREG_SPLIT_NO_EMPTY);
array_splice($deck_array60);
sort($deck_array);

$deck_image imageCreateFromPNG('./img/background.png');

for(
$i 0; isset($deck_array[$i]) && $i 60; ++$i)
{
    
$card_path './img/cards/' $deck_array[$i] . '.png';
    if(
file_exists($card_path))
        
$card_image imageCreateFromPNG($card_path);
    else
        
$card_image imageCreateFromPNG('./img/empty.png');
    
imageCopy($deck_image$card_imagefloor($i 10) * 90 13, ($i 10) * 18 4007777);
    
imageDestroy($card_image);
}

switch(
strtolower($mark_string))
{
    case 
'entropy'  $mark_path 'cards/4sj.png'; break;
    case 
'death'    $mark_path 'cards/4sk.png'; break;
    case 
'gravity'  $mark_path 'cards/4sl.png'; break;
    case 
'earth'    $mark_path 'cards/4sm.png'; break;
    case 
'life'     $mark_path 'cards/4sn.png'; break;
    case 
'fire'     $mark_path 'cards/4so.png'; break;
    case 
'water'    $mark_path 'cards/4sp.png'; break;
    case 
'light'    $mark_path 'cards/4sq.png'; break;
    case 
'air'      $mark_path 'cards/4sr.png'; break;
    case 
'time'     $mark_path 'cards/4ss.png'; break;
    case 
'darkness' $mark_path 'cards/4st.png'; break;
    case 
'aether'   $mark_path 'cards/4su.png'; break;
    default         : 
$mark_path 'empty.png';
}
$mark_image imageCreateFromPNG('./img/' $mark_path);
imageCopy($deck_image$mark_image5634007777);
imageDestroy($mark_image);

imageInterlace($deck_imagetrue);
header('Content-type: image/jpeg');
imageJPEG($deck_imageNULL95);
imageDestroy($deck_image);

?>
We have different pieces of code, but the effect is the same. And with the caching I just finished, each deck is processed only one time, so the script performance is really not the main concern now.

Have fun anyway, and still, great work on your vision of the project ! But maybe you should try something else ?

ftbhrygvn

  • Guest
Re: Elements deck image generator https://elementscommunity.org/forum/index.php?topic=4173.msg49289#msg49289
« Reply #46 on: April 06, 2010, 06:38:15 pm »
Seeing that I have helped with probably all my effort, I have moved to another project now. But it is still in a very infant stage and I'm encountering some problems that I'm trying to sort out. I'm not sure I can get it done so I'm not ready to talk about it right now, but I will when I can.

Re: Elements deck image generator https://elementscommunity.org/forum/index.php?topic=4173.msg181188#msg181188
« Reply #47 on: October 21, 2010, 07:30:17 pm »
Nicely done! but where's shard of readiness @? I'd imagine that this was very trick but you probably had some genius method :D Great Job!! :)

 

blarg: