Example #1
0
foreach ($images as $image) {
    $compare = str_replace($folder, '', $image);
    $compare = str_replace('.full.jpg', '.jpg', $compare);
    $compare = preg_replace('/[^a-zA-Z\\.\\/\\d\\-]|\\.(?!jpg$)/sui', '', $compare);
    foreach ($cards as $id => $card) {
        if ($compare == $card['image']) {
            $import[$image] = $card['image'];
            unset($cards[$id]);
            break;
        }
    }
}
if (!empty($cards)) {
    foreach ($cards as $card) {
        echo 'Missing card: ' . $card['image'] . "\n";
    }
    die;
}
clear_dir(IMAGES . SL . 'full' . SL . $set['id']);
clear_dir(IMAGES . SL . 'small' . SL . $set['id']);
$i = 0;
foreach ($import as $from => $to) {
    $worker = new Transform_Upload_Mtg($from, $to);
    try {
        $worker->process_file();
    } catch (Error_Upload $e) {
    }
    echo ++$i . '/' . count($import) . "\n";
    ob_flush();
    flush();
}
Example #2
0
 public static function get_images($ids)
 {
     $images = Database::get_vector('card', array('id', 'image'), Database::array_in('id', $ids), $ids);
     foreach ($images as $image) {
         if (file_exists(IMAGES . SL . 'small' . SL . $image)) {
             continue;
         }
         $url = preg_replace('/^(\\/.*)(\\/.*)$/ui', 'http://www.mtg.ru/pictures$1_big$2', $image);
         $got = false;
         $i = 0;
         while (!$got && ++$i < 15) {
             usleep(200000);
             $handle = curl_init($url);
             curl_setopt($handle, CURLOPT_RETURNTRANSFER, 1);
             curl_setopt($handle, CURLOPT_BINARYTRANSFER, 1);
             $response = curl_exec($handle);
             $code = curl_getinfo($handle, CURLINFO_HTTP_CODE);
             curl_close($handle);
             if ($code == 404) {
                 $url = 'http://www.mtg.ru/pictures' . $image;
             } elseif (md5($response) != 'b7b25d6d52c197be99ed9093958b6f39') {
                 $got = true;
             }
         }
         $worker = new Transform_Upload_Mtg($response, $image);
         try {
             $worker->process_file();
         } catch (Error_Upload $e) {
         }
     }
 }