Nice linux scripts (edited to auto-create the PSP sets)

All add-on programm and tools for wagic
Locked
ZiRRuSH
Posts: 42
Joined: Sat Jan 29, 2011 11:53 pm

Nice linux scripts (edited to auto-create the PSP sets)

Post by ZiRRuSH »

Found these scripts at http://ark42.com/mtg ... Ark also has a couple nice utilities for windows users as well, ran across his stuff on slightlymagic while digging around. I modified these scripts to automatically retrieve all images in the particular set, name them as the card id, and crop to PSP format for wagic, create the thumbnails, then create two zip files with the original images and one of the PSP set. I suggest checking out his site as well though : )

Card Array Script:
Edit and run this to download the includes file for the next script. Change the set name at the top to whatever set you want to snag, must be the exact name that gatherer uses to pull the set up with. Make the php file executable and run "~$ ./make-cards-array.php > cards.inc" . This file is used with the next script to download the images of the set

Code: Select all

#!/usr/bin/php -q
<?
    //This script's purpose is to get all MTG card information from Wizard's Gatherer
    //and create a php include file with an array of card information.

    //Save as make-cards-array.php (not phps) and make it runnable: chmod 700 make-cards-array.php
    //Generate cards.inc by running this script like: ./make-cards-array.php > cards.inc

    //Change this to whatever set you wish to get the information of.

    $cardsets = array(
        "Masters Edition IV",
	
    );

    function clean_text($line) {
        return html_entity_decode(strtr(htmlentities($line, ENT_QUOTES, 'UTF-8'), array(
                '&mdash;' => '-',
                '&aelig;' => 'ae',
                '&AElig;' => 'Ae',
                '&aacute;' => 'a',
                '&acirc;' => 'a',
                '&iacute;' => 'i',
                '&ouml;' => 'o',
                '&uacute;' => 'u',
                '&ucirc;' => 'u',
                '  ' => ' '
            )), ENT_QUOTES);
    }

    function get_card_data_piece($f) {
        $rawline = fgets($f, 4096);
        $rawline = fgets($f, 4096);
        $rawline = fgets($f, 4096);
        return clean_text(trim(strip_tags($rawline)));
    }

    ini_set('memory_limit', '64M');

    $intable = false;
    $cards = $card = $pieces = array();
    foreach( $cardsets as $set ) {
        $f = fopen('http://gatherer.wizards.com/Pages/Search/Default.aspx?output=spoiler&method=text&set=["'.urlencode($set).'"]', 'r');
        $foundany = false;
        while( !feof($f) ) {
            $rawline = fgets($f, 4096);
            if( strstr($rawline, '</table>') ) $intable = false;

            if( $intable ) {
                $line = clean_text(trim(strip_tags($rawline)));
                if( substr($line, 0, 5) == 'Name:' ) {
                    $line = get_card_data_piece($f);
                    $second = '';
                    if( preg_match('/XX(.*) \((.*)\)/', $line, $matches) ) {
                        $line = $matches[1];
                    } else if( preg_match('/((.*) \/\/ (.*)) \((.*)\)/', $line, $matches) ) {
                        $line = $matches[1];
                        if( $matches[3] == $matches[4] ) {
                            $second = 'split';
                        }
                    } else if( preg_match('/(.*) \((.*)\)/', $line, $matches) ) {
                        $second = 'flip';
                        $line = $matches[1];
                        $card[extra] = "-----\n$matches[2]\n";
                    }
                    $card[name] = $line;
                } else if( substr($line, 0, 5) == 'Cost:' ) {
                    $card[cost] = get_card_data_piece($f);
                } else if( substr($line, 0, 5) == 'Type:' ) {
                    $card[type] = get_card_data_piece($f);
                } else if( substr($line, 0, 8) == 'Pow/Tgh:' ) {
                    $line = substr(get_card_data_piece($f), 1, -1);
                    $pt = explode('/', $line);
                    $card[power] = $pt[0];
                    $card[toughness] = $pt[1];
                } else if( substr($line, 0, 8) == 'Loyalty:' ) {
                    $card[toughness] = substr(get_card_data_piece($f), 1, -1);
                } else if( substr($line, 0, 11) == 'Set/Rarity:' ) {
                    $sr = explode(',', strtr(get_card_data_piece($f), array('Mythic Rare' => 'Mythic')));
                    for( $i = 0; $i < count($sr); $i++ ) {
                        $p = strrpos($sr[$i], ' ');
                        $card[sets] .= trim(substr($sr[$i], 0, $p)) . ',';
                    }
                    $card[sets] = strtr(substr($card[sets], 0, -1), array('"Timeshifted"' => 'Timeshifted'));
                    for( $i = 0; $i < count($sr); $i++ ) {
                        if( strpos($sr[$i], $set) !== false ) break;
                    }
                    if( $i >= count($sr) ) $i = 0;
                    $sr = explode(' ', trim($sr[$i]));
                    $card[rarity] = $sr[count($sr) - 1];
                } else if( substr($line, 0, 11) == 'Rules Text:' ) {
                    $card[rules] = get_card_data_piece($f);
                    for( $i = 0; $i < 100; $i++ ) {
                        $rawline = fgets($f, 4096);
                        if( strpos($rawline, '</td>') !== false ) break;
                        $card[rules] .= "\n" . clean_text(trim(strip_tags($rawline)));
                    }
                } else if( strpos($rawline, '<br />') !== false ) {
                    $card[set] = strtr($set, array('"Timeshifted"' => 'Timeshifted'));

                    if( $card[rarity] == 'Special' ) {
                        if( $cards[$card[name]][rarity] != '' ) {
                            $card[rarity] = $cards[$card[name]][rarity];
                        }
                    }

                    if( $second != '' ) {
                        $card[second] = $second;
                        $pieces[$card[name]] = $card;
                    } else {
                        $cards[$card[name]] = $card;
                    }

                    $card = array();

                    $foundany = true;
                }
            }

            if( strstr($rawline, '<div class="textspoiler">') ) $intable = true;
        }
        fclose($f);

        if( !$foundany ) {
            die("Found no cards for $set\n");
        }
    }

    foreach( $pieces as $card ) {
        if( !isset($cards[$card[name]]) ) {
            $cards[$card[name]] = $card;
        } else if( $card[second] == 'split' ) {
            $cards[$card[name]][cost] .= ' // ' . $card[cost];
            $cards[$card[name]][type] .= ' // ' . $card[type];
            $cards[$card[name]][rules] .= '//' . $card[rules];
        } else if( $card[second] == 'flip' ) {
            $cards[$card[name]][rules] .= $card[extra] . $card[type] . "\n";
            if( $card[power] != '' || $card[toughness] != '' ) $cards[$card[name]][rules] .= "$card[power]/$card[toughness]\n";
            $cards[$card[name]][rules] .= $card[rules];
        }
    }

    ksort($cards);

    function someslashes($str) {
        return strtr($str, array('"' => '\"', '\\' => '\\\\'));
    }

    echo "<" . "?\n\$cardsets = array(\n";
    $first = true;
    foreach( $cardsets as $set ) {
        $set = strtr($set, array('"Timeshifted"' => 'Timeshifted'));
        if( $first ) {
            $first = false;
        } else {
            echo ",\n";
        }
        echo "\t\"$set\"";
    }
    echo "\n);\n";

    echo "\$cards = array(\n";
    $first = true;
    foreach( $cards as $card ) {
        if( $first ) {
            $first = false;
        } else {
            echo ",\n";
        }
        echo "\t\"" . someslashes(strtolower($card[name])) . "\" => array(\n" .
            "\t\t\"name\" => \"" . someslashes($card[name]) . "\",\n",
            "\t\t\"cost\" => \"" . someslashes($card[cost]) . "\",\n",
            "\t\t\"type\" => \"" . someslashes($card[type]) . "\",\n",
            "\t\t\"set\" => \"" . someslashes($card[set]) . "\",\n",
            "\t\t\"sets\" => \"" . someslashes($card[sets]) . "\",\n",
            "\t\t\"rarity\" => \"" . someslashes($card[rarity]) . "\",\n",
            "\t\t\"power\" => \"" . someslashes($card[power]) . "\",\n",
            "\t\t\"toughness\" => \"" . someslashes($card[toughness]) . "\",\n",
            "\t\t\"rules\" => \"" . strtr(someslashes($card[rules]), array("\n" => '\n', 'T ' => 'T: ')) . "\"\n" .
            "\t)";
    }
    echo "\n);\n?" . ">\n";
?>
The gatherer image gatherer script (to be used with the cards.inc created from the script above):

Code: Select all

 #!/usr/bin/php -q
    <?

    //This script's purpose is to get all card images from the most recent MTG set and create 3 separate directories and zip files full of jpgs.
    //Origs will contain the exact jpg file as downloaded.
    //Fulls will contain a slighly cropped (to remove the rounded black border's corner), and slightly blown up and sharpened image for each jpg.
    //Crops will contain the cropped artwork from the top portion of the card with no borders or rules text for each jpg.

    //Save as get-gatherer-images.php (not phps) and make it runnable: chmod 700 get-gatherer-images.php
    //Generate 3 directories full of jpgs as well as 3 zip files by running this script like: ./get-gatherer-images.php

    //This script requires that you have access to the following 3 somewhat common linux command line utilities:
    //  wget located at /usr/bin/wget in order to quickly fetch and save an image from a url
    //  imagemagick's convert program at /usr/local/bin/convert in order to crop and resize images
    //  zip at /usr/bin/zip in order to create the zip files
    //Please check that these utilities are available and at the locations listed above, or this script will not work.

        ini_set('memory_limit', '64M');

        require_once('cards.inc');

        @mkdir('Origs');
        @mkdir('PSP');
        @mkdir('PSP/thumbnails');

        $set = $cardsets[count($cardsets) - 1];
        foreach( $cards as $card ) {
            if( $card[set] == $set ) {
                echo "Card:$card[name] ";
                $searchname = strtr(urlencode(strtr($card[name], array(' ' => '\s'))), array(
                    'Ae' => '(Ae|%c3%86)',
                    'ae' => '(ae|%c3%a6)'
                ));
                $f = fopen('http://gatherer.wizards.com/Pages/Search/Default.aspx?name=[m/^'.$searchname.'$/]', 'r');
                $datas = stream_get_meta_data($f);
                fclose($f);
                foreach( $datas[wrapper_data] as $data ) {
                    if( substr($data, 0, 9) == 'Location:' ) {
                        $num = substr($data, strrpos($data, '=') + 1);
                        echo "ID:$num ";
                        $filename = $num;
                        if( $card[name] == 'Plains' || $card[name] == 'Island' || $card[name] == 'Swamp' || $card[name] == 'Mountain' || $card[name] == 'Forest' ) {
                            $filename .= '1';
                        }
                        shell_exec("/usr/bin/wget -q -O \"Origs/$filename.jpg\" \"http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=$num&type=card\" > /dev/null");
                        echo "Downloaded ";
                        shell_exec("/usr/bin/convert \"Origs/$num.jpg\" -crop 200x285+13+12 -quality 80 \"PSP/$num.jpg\"");
                        shell_exec("/usr/bin/convert \"PSP/$num.jpg\" -resize 45x64 -quality 80 \"PSP/thumbnails/$num.jpg\"");
                        echo "Converted for Wagic";
                    }
                }
                echo "\n";
            }
        }

        shell_exec("/usr/bin/zip -9 Origs.$searchname.zip Origs/*");
        shell_exec("/usr/bin/zip -0 $searchname.zip PSP/*");
    ?>

I've got the card-array script setup to get the ME4 set by default, but as said... just change it to whatever set you want to snag. May also need to check the path to your binaries for zip, convert, and wget. Depending on your distro and config, they might be located in /usr/local/bin. Also note, unless gatherer has the images of the tokens up... this script doesn't take care of them. Regardless, I find it very usefull and time saving. Hope you all get some use out of it : )
njacssca
Posts: 1
Joined: Tue Jun 14, 2022 2:37 pm

Re: Nice linux scripts (edited to auto-create the PSP sets)

Post by njacssca »

فن عريق وهناك عدة اختيارات من الصور يمكن استخدام تقنية الأبيض والأسود عليها. يُفضل أن تحتوي الصورة على درجات الأبيض ودرجات الأسود جميعها التي تقارب السبع درجات حتى يكتمل التميّز. بعض الكاميرات الرقمية يوجد بها خيار التصوير الأبيض والأسود وبعض الكاميرات لا يوجد بها هذا الخيار لكن يمكن للمصوّر تحويل الصور إلى الأبيض والأسود عن طريق البرامج المرافقة للكاميرا أو برنامج (الفوتوشوب) الغني عن التعريف.

استديو تصوير نسائي
يعتبر التعرف على طرق التعامل مع الكاميرا أول خطوات تعلم عن التصوير الفوتوغرافي، لهذا يجب البدء بالتعرف على الكاميرا وطريقة استعمالها وما هي إمكانياتها، من خلال قراءة دليل الاستخدام، كما يمكن أيضاً استخراج الكثير من المعلومات من الشبكة العنكبوتية من المواقع الخاصة بنوع الكاميرا المستعملة.
يفضل أن يتم استعمال الحامل الثلاثي الخاص بالكاميرا عند الرغبة بالتقاط عدة صور مع بعضها، حيث إنّ ذلك يساعد على تثبيت الكاميرا بطريقة أفضل.
مصور فوتوغرافي
هذه العناصر تساعد على تحسين الأداء في التصوير، وتمنح القدرة على تقييم الصورة، وهي: الفكرة: وهي أساس كل صورة إبداعيّة، فالصورة تحاول إيصال رسالة معينّة أو لقطة جمالية مُبهرة. زاوية الالتقاط: وهي تعتمد على الفكرة، حيث إنّ لكل فكرة زاوية التقاط توضّحها وتزيدها جمالاً. الإضاءة: وهي تعلب دوراً كبيراً في إيصال فكرة الصورة، فلكل فكرة إضاءة معيّنة، ولكل إضاءة خصائص معيّنة يجب معرفتها لتحديد ما يُناسب الفكرة.

تصوير منتجات
Jeremy123
Posts: 5
Joined: Sun Jan 23, 2022 7:47 pm

Re: Nice linux scripts (edited to auto-create the PSP sets)

Post by Jeremy123 »

Thank you for this resource. why not try this out
lemieuxhelm
Posts: 2
Joined: Tue Jun 28, 2022 12:25 pm

Re: Nice linux scripts (edited to auto-create the PSP sets)

Post by lemieuxhelm »

These scripts are really awesome! I appreciate your effort in sharing this. stump removal Dallas photo booth rental Manahawkin New Jersey sunsetter awnings Joseph
Locked