Exemple #1
0
	public function render () {
		global $config;

		echo $this->card . '...';
		$card = $this->card;
		$settings = $this->getSettings();
		$costColors = Card::getCostColors($card->cost);
		$white = '255,255,255';

		$canvas = imagecreatetruecolor(1050, 736);

		// Art image.
		$this->drawArt($canvas, $card->artFileName, $settings['art.top'], $settings['art.left'], $settings['art.bottom'], $settings['art.right'], !$config['art.keep.aspect.ratio']);

		echo '.';

		// Background image.
		$bgImage = @imagecreatefrompng('images/plane/plane.png');
		imagecopy($canvas, $bgImage, 0, 0, 0, 0, 1050, 736);

		echo '.';

		// Set and rarity.
		$rarityLeft = $this->drawRarity($canvas, $card->rarity, $card->set, $settings['rarity.right'], $settings['rarity.center.y'], $settings['rarity.height'], $settings['rarity.width'], false);

		// Card title.
		$this->drawText($canvas, $settings['title.x'], $settings['title.y'], null, $card->getDisplayTitle(), $this->font('title'));

		echo '.';

		// Type.
		$this->drawText($canvas, $settings['type.x'], $settings['type.y'], null, $card->type, $this->font('type'));

		//Chaos Symbol
		$this->drawSymbol($canvas, 632, 115, 50, 'C', null);

		// Legal text.
		if (!preg_match('/(.*\n)(.*?)$/s', $card->legal, $matches)) error('Missing chaos ability from legal text: ' . $card->title);
		$this->drawLegalAndFlavorText($canvas, $settings['text.top'], $settings['text.left'], $settings['text.bottom'], $settings['text.right'], $matches[1], null, $this->font('text'), 0);
		$this->drawLegalAndFlavorText($canvas, $settings['chaos.top'], $settings['chaos.left'], $settings['chaos.bottom'], $settings['chaos.right'], $matches[2], null, $this->font('text'), 0);

		// Artist and copyright.
		// The artist color is white if the frame behind it is black.
		$footerColor = '255,255,255';
		if ($card->artist) {
			if ($settings['card.artist.gears']) {
				$artistSymbol = '{gear}';
			} else {
				$artistSymbol = '{brush}';
			}
			$this->drawText($canvas, $settings['artist.x'], $settings['artist.y'], null, $artistSymbol . $card->artist, $this->font('artist', 'color:' . $footerColor));
		}
		if ($card->copyright) $this->drawText($canvas, $settings['copyright.x'], $settings['copyright.y'], null, $card->copyright, $this->font('copyright', 'color:' . $footerColor));

		echo "\n";
		return $canvas;
	}
Exemple #2
0
 public function render()
 {
     global $config;
     echo $this->card . '...';
     $card = $this->card;
     $settings = $this->getSettings();
     $costColors = Card::getCostColors($card->cost);
     $white = '255,255,255';
     $useMulticolorFrame = strlen($costColors) == 2;
     $canvas = imagecreatetruecolor(736, 1050);
     // Art image.
     $this->drawArt($canvas, $card->artFileName, $settings['art.top'], $settings['art.left'], $settings['art.bottom'], $settings['art.right'], !$config['art.keep.aspect.ratio']);
     echo '.';
     // Background image.
     $borderImage = null;
     $greyTitleAndTypeOverlay = null;
     if ($card->isArtefact()) {
         $bgImage = @imagecreatefrompng('images/eighth/leveler/cards/Art.png');
     } else {
         if ($useMulticolorFrame || $card->isDualManaCost()) {
             // Multicolor frame.
             if ($settings['card.multicolor.gold.frame']) {
                 $bgImage = @imagecreatefrompng("images/eighth/leveler/cards/Gld{$costColors}" . ".png");
             } else {
                 $bgImage = @imagecreatefrompng("images/eighth/leveler/cards/{$costColors}" . ".png");
             }
             if (!$bgImage) {
                 error("Background image not found for color: {$costColors}");
             }
         } else {
             // Mono color frame.
             $bgImage = @imagecreatefrompng('images/eighth/leveler/cards/' . $card->color . '.png');
             if (!$bgImage) {
                 error('Background image not found for color "' . $card->color . '"');
             }
         }
     }
     imagecopy($canvas, $bgImage, 0, 0, 0, 0, 736, 1050);
     imagedestroy($bgImage);
     // Casting cost.
     $costLeft = $this->drawCastingCost($canvas, $card->getCostSymbols(), $card->isDualManaCost() ? $settings['cost.top.dual'] : $settings['cost.top'], $settings['cost.right'], $settings['cost.size'], true);
     echo '.';
     // Set and rarity.
     $rarityLeft = $this->drawRarity($canvas, $card->rarity, $card->set, $settings['rarity.right'], $settings['rarity.center.y'], $settings['rarity.height'], $settings['rarity.width'], false);
     // Card title.
     $this->drawText($canvas, $settings['title.x'], $settings['title.y'], $costLeft - $settings['title.x'], $card->getDisplayTitle(), $this->font('title'));
     echo '.';
     // Type.
     $this->drawText($canvas, $settings['type.x'], $settings['type.y'], $rarityLeft - $settings['type.x'], $card->type, $this->font('type'));
     // Legal text.
     if (!preg_match_all('/(.*?)\\r?\\n(.*?) ([0-9\\-\\+]+?)\\r?\\n([0-9\\*\\-\\+\\/]{3,})\\r?\\n(.*?)\\r?\\n?((?<=\\n)[^\\s]*?(?=\\s)) ([0-9\\-\\+]+?)\\r?\\n([0-9\\*\\-\\+\\/]{3,})\\r?\\n?(.*?)$/s', $card->legal, $matches)) {
         error('Wrong format for legal text: ' . $card->title);
     }
     //1
     $this->drawText($canvas, $settings['pt.1.center.x'], $settings['pt.1.center.y'], $settings['pt.1.width'], $card->pt, $this->font('pt'));
     $this->drawLegalAndFlavorText($canvas, $settings['text.1.top'], $settings['text.1.left'], $settings['text.1.bottom'], $settings['text.1.right'], $matches[1][0], null, $this->font('text'), 0);
     //2
     $this->drawText($canvas, $settings['pt.2.center.x'], $settings['pt.2.center.y'], $settings['pt.2.width'], $matches[4][0], $this->font('pt'));
     $this->drawText($canvas, $settings['name.2.center.x'], $settings['name.2.center.y'], $settings['name.2.width'], $matches[2][0], $this->font('pt', 'glow:true'));
     $this->drawText($canvas, $settings['level.2.center.x'], $settings['level.2.center.y'], $settings['level.2.width'], $matches[3][0], $this->font('pt', 'glow:true'));
     $this->drawLegalAndFlavorText($canvas, $settings['text.2.top'], $settings['text.2.left'], $settings['text.2.bottom'], $settings['text.2.right'], $matches[5][0], null, $this->font('text'), 0);
     //3
     $this->drawText($canvas, $settings['pt.3.center.x'], $settings['pt.3.center.y'], $settings['pt.3.width'], $matches[8][0], $this->font('pt'));
     $this->drawText($canvas, $settings['name.3.center.x'], $settings['name.3.center.y'], $settings['name.3.width'], $matches[6][0], $this->font('pt', 'glow:true'));
     $this->drawText($canvas, $settings['level.3.center.x'], $settings['level.3.center.y'], $settings['level.3.width'], $matches[7][0], $this->font('pt', 'glow:true'));
     $this->drawLegalAndFlavorText($canvas, $settings['text.3.top'], $settings['text.3.left'], $settings['text.3.bottom'], $settings['text.3.right'], $matches[9][0], null, $this->font('text'), 10);
     // Artist and copyright.
     // The artist color is white if the frame behind it is black.
     $footerColor = '0,0,0';
     if ($card->isLand()) {
         $footerColor = '255,255,255';
     } else {
         if ($card->color == 'B' && !$card->isArtefact()) {
             $footerColor = '255,255,255';
         } else {
             if ($costColors == 'B' && !$card->isArtefact()) {
                 $footerColor = '255,255,255';
             } else {
                 if (stripos($card->englishType, 'Eldrazi') !== false) {
                     $footerColor = '255,255,255';
                 } else {
                     if ($useMulticolorFrame) {
                         // Only multicolor frames with a bottom left color of black should use a white footer.
                         if (strlen($costColors) <= 2 && substr($costColors, 0, 1) == 'B' || strlen($costColors) >= 3 && substr($costColors, 2, 1) == 'B') {
                             $footerColor = '255,255,255';
                         }
                     }
                 }
             }
         }
     }
     if ($card->artist) {
         if ($settings['card.artist.gears']) {
             $artistSymbol = '{gear}';
         } else {
             $artistSymbol = '{brush}';
         }
         $this->drawText($canvas, $settings['artist.x'], $settings['artist.y'], null, $artistSymbol . $card->artist, $this->font('artist', 'color:' . $footerColor));
     }
     if ($card->copyright) {
         $this->drawText($canvas, $settings['copyright.x'], $settings['copyright.y'], null, $card->copyright, $this->font('copyright', 'color:' . $footerColor));
     }
     echo "\n";
     return $canvas;
 }
Exemple #3
0
	public function __construct ($mwsFileName) {
		$mwsFile = fopen_utf8($mwsFileName, 'rb');
		if (!$mwsFile) error('Unable to open masterbase CSV file: ' . $mwsFileName);
		
		echo "Processing MWS masterbase...";

		// windows-1252
		//$csv = new CSV(';', "\r\n", '"'); // Cell separator, row separator, value enclosure.

		//$csv->setContent(file_get_contents($mwsFileName, false , null)); // Parse the string content.

		//$rows = $csv->getArray();
		$i = 0;
		while (($row = fgetcsv($mwsFile, 6000, ';', '"')) !== FALSE) {
		//foreach($rows as $row){
			if($i++ == 0) continue; //skip first line
			if ($i++ % 50 == 0) echo '.';

			// Extract.
			$title = (string)trim($row[0]);
			$set = (string)trim($row[1]);
			$color = (string)trim($row[4]);
			$type = (string)trim($row[6]);
			$p = (string)trim($row[8]);
			$t = (string)trim($row[9]);
			$flavor = (string)trim($row[10]);
			$rarity = (string)trim($row[11]);
			$cost = (string)trim($row[5]);
			$legal = trim($row[7]);
			$pic = (string)trim($row[2]);
			$artist = (string)trim($row[12]);
			$collectorNumber = (string)trim($row[13]);

			// Title.
			if ($set == 'VG') $title = 'Avatar: ' . $title;

			// Casting cost.
			$cost = $this->replaceDualManaSymbols($cost);
			$cost = preg_replace('/([0-9]+)/', '{\\1}', $cost); //
			$cost = preg_replace('/([WUBRGXYZ])/', '{\\1}', $cost);
			$cost = preg_replace('/{{([0-9XYZWUBRG])}{([WUBRG])}}/', '{\\1\\2}', $cost);

			// Color.
			if ($color == 'Z/Z') {
				// Determine split card colors.
				$cost1 = substr($cost, 0, strpos($cost, '/'));
				$colors = Card::getCostColors($cost1);
				$color = strlen($colors) == 1 ? $colors : 'Gld';

				$color .= '/';

				$cost2 = substr($cost, strpos($cost, '/') + 1);
				$colors = Card::getCostColors($cost2);
				$color .= strlen($colors) == 1 ? $colors : 'Gld';
			}

			//php5 fixups
			$flavor = str_replace("\xA0", '', $flavor);
			$flavor = iconv('windows-1250', 'utf-8', $flavor);
			$legal = iconv('windows-1250', 'utf-8' ,$legal);
			$artist = iconv('windows-1250', 'utf-8' ,$artist);
			//convert title and type just in case
			$title = iconv('windows-1250', 'utf-8', $title);
			$type = iconv('windows-1250', 'utf-8' ,$type);

			// Type.
			$type = str_replace(' - ', ' — ', $type);

			// Legal.
			$legal = $this->replaceDualManaSymbols($legal);
			$legal = preg_replace('/\%([0-9]+)/', '{\\1}', $legal);
			$legal = preg_replace('/\%([WUBRGTXYZ])/', '{\\1}', $legal);
			$legal = preg_replace('/\%([C])/', '{Q}', $legal);
			$legal = preg_replace('/#([^#]+)# – /', '\\1 – ', $legal); // Remove italics from ability keywords.
			$legal = str_replace("\r\n----\r\n", "\n-----\n", $legal); // Flip card separator.
			$legal = str_replace('Creature - ', 'Creature — ', $legal);
			$legal = str_replace(' upkeep - ', ' upkeep—', $legal);
			$legal = str_replace(' - ', ' — ', $legal);
			$legal = str_replace('AE', 'Æ', $legal);
			$legal = str_replace(".]", ".)", $legal);
			$legal = str_replace("\r\n", "\n", $legal);
			// Fix vanguard inconsistencies.
			if (preg_match('/Starting & Max[^\+\-]+([\+\-][0-9]+)[^\+\-]+([\+\-][0-9]+)/', $legal, $matches))
				$legal = 'Hand ' . $matches[1] . ', Life ' . $matches[2] . "\n" . substr($legal, 0, strpos($legal, ' Starting & Max'));
			if (preg_match('/Hand Size[^\+\-]+([\+\-][0-9]+)[^\+\-]+([\+\-][0-9]+)\.?/', $legal, $matches))
				$legal = 'Hand ' . $matches[1] . ', Life ' . $matches[2] . "\n" . substr($legal, 0, strpos($legal, 'Hand Size'));
			$legal = trim($legal);

			// Flavor.
			$flavor = str_replace("'", '’', $flavor); // ' to ’
			$flavor = preg_replace('/"([^"]*)"/', '“\\1”', $flavor); // "text" to “text”
			$flavor = preg_replace("/(.*[^.]) '([^']*)'/", "\\1 ‘\\2’", $flavor); // 'text' to ‘text’
			$flavor = preg_replace('/(.*[^.]) ’(.*)’/', '\\1 ‘\\2’', $flavor); // ’text’ to ‘text’
			$flavor = str_replace('”’', '’”', $flavor); // ”’ to ’”
			$flavor = str_replace('‘”', '”‘', $flavor); // ‘” to ”‘
			$flavor = str_replace('“’', '“‘', $flavor); // “’ to “‘
			$flavor = str_replace(',’', '’,', $flavor); // ,’ to ’,
			$flavor = preg_replace("/\r\n- ?/", "\n—", $flavor); // - to —
			$flavor = preg_replace("/\r\n#- ?/", "\n#—", $flavor);
			$flavor = preg_replace("/ - /", "—", $flavor);
			$flavor = str_replace('AE', 'Æ', $flavor);
			$flavor = str_replace("\r\n", "\n", $flavor);
			$flavor = str_replace('"', '”', $flavor); // " to ”

			// Store.
			$card = new Card();
			$card->title = $title;
			$card->set = $set;
			$card->color = $color;
			$card->type = $type;
			$card->pt = ($p != "" && $t !="") ? $p . '/' . $t : (preg_match('/%([0-9]+)#/', $p, $matches) ? "/$matches[1]" : '');
			$card->flavor = $flavor;
			$card->rarity = $rarity;
			$card->cost = $cost;
			$card->legal = $legal;
			$card->pic = $pic;
			$card->artist = $artist;
			$card->collectorNumber = $collectorNumber;
			$this->cards[] = $card;
		}

		// Compute total cards in each set.
		$setToCollectorNumbers = array();
		foreach ($this->cards as $card) {
			// Only count cards with collector numbers.
			if (!$card->collectorNumber) continue;
			// Don't count the same collector number twice.
			if (!@$setToCollectorNumbers[$card->set]) $setToCollectorNumbers[$card->set] = array();
			if (@$setToCollectorNumbers[$card->set][$card->collectorNumber]) continue;

			$setToCollectorNumbers[$card->set][$card->collectorNumber] = true;
		}
		foreach ($this->cards as $card) {
			if (!$card->collectorNumber) continue;
			// Try hardcoded value first.
			$cardsInSet = MasterBase::getTotalCardsInSet($card->set);
			// Then try computed vallue.
			if (!$cardsInSet && @$setToCollectorNumbers[$card->set]) $cardsInSet = count($setToCollectorNumbers[$card->set]);
			if (!$cardsInSet) continue;
			$card->collectorNumber .= '/' . $cardsInSet;
		}
	}
 public function render()
 {
     global $config;
     echo $this->card . '...';
     $card = $this->card;
     $settings = $this->getSettings();
     $costColors = Card::getCostColors($card->cost);
     $useMulticolorFrame = strlen($costColors) == 2 && strpos($settings['card.multicolor.frames'], strval(strlen($costColors))) !== false;
     $canvas = imagecreatetruecolor(736, 1050);
     // Art image.
     $this->drawArt($canvas, $card->artFileName, $settings['art.top'], $settings['art.left'], $settings['art.bottom'], $settings['art.right'], !$config['art.keep.aspect.ratio']);
     echo '.';
     $cards = explode("\n-----\n", $card->legal);
     $legal1 = $cards[0];
     if (preg_match("/(.*?)\n(.*?)\n(.*?)\n(.*)/s", $cards[1], $matches)) {
         $title2 = $matches[1];
         $type2 = $matches[2];
         $pt2 = $matches[3];
         $legal2 = $matches[4];
     } else {
         preg_match("/(.*?)\n(.*?)\n(.*)/s", $cards[1], $matches);
         $title2 = $matches[1];
         $type2 = $matches[2];
         $pt2 = '';
         $legal2 = $matches[3];
     }
     // Background image, border image, and grey title/type image.
     $borderImage = null;
     $greyTitleAndTypeOverlay = null;
     if ($card->isLand()) {
         // Land frame.
         $landColors = @$this->writer->titleToLandColors[strtolower($card->title)];
         if (!$landColors) {
             error('Land color missing for card: ' . $card->title);
         }
         if (strlen($landColors) > 1) {
             $useMulticolorLandFrame = strpos($settings['card.multicolor.land.frames'], strval(strlen($landColors))) !== false;
             if (!$useMulticolorLandFrame) {
                 $landColors = 'A';
             }
         }
         $bgImage = @imagecreatefrompng("images/eighth/flip/land/{$landColors}.png");
         if (!$bgImage) {
             error('Background image not found for land color "$landColors": ' . $card->title);
         }
         // Grey title/type image.
         if (strlen($landColors) >= 2 && $settings['card.multicolor.grey.title.and.type']) {
             $greyTitleAndTypeOverlay = @imagecreatefrompng('images/eighth/flip/cards/C-overlay.png');
             if (!$greyTitleAndTypeOverlay) {
                 error('Image not found: C-overlay.png');
             }
         }
     } else {
         if ($useMulticolorFrame || $card->isDualManaCost()) {
             // Multicolor frame.
             $bgImage = @imagecreatefrompng("images/eighth/flip/cards/{$costColors}.png");
             if (!$bgImage) {
                 error("Background image not found for color: {$costColors}");
             }
             // Grey title/type image.
             if ($settings['card.multicolor.grey.title.and.type']) {
                 $greyTitleAndTypeOverlay = @imagecreatefrompng('images/eighth/flip/cards/C-overlay.png');
                 if (!$greyTitleAndTypeOverlay) {
                     error('Image not found: C-overlay.png');
                 }
             }
         } else {
             // Mono color frame.
             $bgImage = @imagecreatefrompng('images/eighth/flip/cards/' . $card->color . '.png');
             if (!$bgImage) {
                 error('Background image not found for color "' . $card->color . '" in frame dir: flips');
             }
             // Border image.
             if (strlen($costColors) == 2 && $settings['card.multicolor.dual.borders']) {
                 $borderImage = @imagecreatefrompng("images/eighth/flips/borders/{$costColors}.png");
             }
         }
     }
     imagecopy($canvas, $bgImage, 0, 0, 0, 0, 736, 1050);
     imagedestroy($bgImage);
     if ($borderImage) {
         imagecopy($canvas, $borderImage, 0, 0, 0, 0, 736, 1050);
         imagedestroy($borderImage);
     }
     if ($greyTitleAndTypeOverlay) {
         imagecopy($canvas, $greyTitleAndTypeOverlay, 0, 0, 0, 0, 736, 1050);
         imagedestroy($greyTitleAndTypeOverlay);
     }
     // Power / toughness.
     if ($card->pt) {
         if ($useMulticolorFrame || $card->isDualManaCost()) {
             $image = @imagecreatefrompng('images/eighth/flip/pt/' . substr($costColors, -1, 1) . 'u.png');
         } else {
             $image = @imagecreatefrompng('images/eighth/flip/pt/' . $card->color . 'u.png');
         }
         if (!$image) {
             error("Power/toughness image not found for color: {$card->color}");
         }
         imagecopy($canvas, $image, 0, 0, 0, 0, 736, 1050);
         imagedestroy($image);
         $this->drawText($canvas, $settings['pt.upper.center.x'], $settings['pt.upper.center.y'], $settings['pt.upper.width'], $card->pt, $this->font('pt'));
         $ptLeft = $settings['pt.upper.center.x'] - $settings['pt.upper.width'];
     } else {
         $ptLeft = $settings['rarity.right'];
     }
     // Casting cost.
     $costLeft = $this->drawCastingCost($canvas, $card->getCostSymbols(), $card->isDualManaCost() ? $settings['cost.top.dual'] : $settings['cost.top'], $settings['cost.right'], $settings['cost.size'], true);
     echo '.';
     // Set and rarity.
     if (!$card->isBasicLand() || $settings['card.basic.land.set.symbols']) {
         $this->drawRarity($canvas, $card->rarity, $card->set, $settings['rarity.right'], $settings['rarity.center.y'], $settings['rarity.height'], $settings['rarity.width'], false);
     }
     // Card title.
     $this->drawText($canvas, $settings['title.x'], $settings['title.y'], $costLeft - $settings['title.x'], $card->getDisplayTitle(), $this->font('title'));
     echo '.';
     // Type.
     $this->drawText($canvas, $settings['type.x'], $settings['type.upper.y'], $ptLeft - $settings['type.x'], $card->type, $this->font('type'));
     $this->drawLegalAndFlavorText($canvas, $settings['text.upper.top'], $settings['text.left'], $settings['text.upper.bottom'], $settings['text.right'], $legal1, '', $this->font('text'), 0);
     echo '.';
     // Flip side.
     if ($pt2) {
         if ($useMulticolorFrame || $card->isDualManaCost()) {
             $image = @imagecreatefrompng('images/eighth/flip/pt/' . substr($costColors, 0, 1) . 'd.png');
         } else {
             $image = @imagecreatefrompng('images/eighth/flip/pt/' . $card->color . 'd.png');
         }
         if (!$image) {
             error("Power/toughness image not found for color: {$color}");
         }
         imagecopy($canvas, $image, 0, 0, 0, 0, 736, 1050);
         imagedestroy($image);
         $canvasTmp = imagerotate($canvas, 180, 0, -1);
         imagedestroy($canvas);
         $canvas = $canvasTmp;
         $this->drawText($canvas, $settings['pt.lower.center.x'], $settings['pt.lower.center.y'], $settings['pt.lower.width'], $pt2, $this->font('pt'));
         $ptLeft = $settings['pt.lower.center.x'] - $settings['pt.lower.width'];
     } else {
         $canvasTmp = imagerotate($canvas, 180, 0, -1);
         imagedestroy($canvas);
         $canvas = $canvasTmp;
         $ptLeft = $settings['rarity.right'];
     }
     // Card title.
     $title2 = str_replace('AE', 'Æ', $title2);
     $title2 = str_replace("'", '’', $title2);
     $this->drawText($canvas, $settings['title.x'], $settings['title.lower.y'], $settings['cost.right'] - $settings['title.x'], $title2, $this->font('title'));
     echo '.';
     // Type.
     $this->drawText($canvas, $settings['type.x'], $settings['type.lower.y'], $ptLeft - $settings['type.x'], $type2, $this->font('type'));
     $this->drawLegalAndFlavorText($canvas, $settings['text.lower.top'], $settings['text.left'], $settings['text.lower.bottom'], $settings['text.right'], $legal2, '', $this->font('text'), 0);
     // Back to normal orientation.
     $canvas = imagerotate($canvas, 180, 0, -1);
     // Artist and copyright.
     // The artist color is white if the frame behind it is black.
     $footerColor = '0,0,0';
     if ($card->isLand()) {
         $footerColor = '255,255,255';
     } else {
         if ($costColors == 'B') {
             $footerColor = '255,255,255';
         } else {
             if ($useMulticolorFrame) {
                 // Only multicolor frames with a bottom left color of black should use a white footer.
                 if (strlen($costColors) <= 2 && substr($costColors, 0, 1) == 'B' || strlen($costColors) >= 3 && substr($costColors, 2, 1) == 'B') {
                     $footerColor = '255,255,255';
                 }
             }
         }
     }
     if ($card->artist) {
         if ($settings['card.artist.gears']) {
             $artistSymbol = '{gear}';
         } else {
             $artistSymbol = '{brush}';
         }
         $this->drawText($canvas, $settings['artist.x'], $settings['artist.y'], null, $artistSymbol . $card->artist, $this->font('artist', 'color:' . $footerColor));
     }
     if ($card->copyright) {
         $this->drawText($canvas, $settings['copyright.x'], $settings['copyright.y'], null, $card->copyright, $this->font('copyright', 'color:' . $footerColor));
     }
     echo "\n";
     return $canvas;
 }
Exemple #5
0
function promptCardInfo ($cardType, $isLastCard = true) {
	global $writer;

	$card = new Card();

	echo "Title:\n";
	$card->title = upperCaseWords(trim(fgets(STDIN)));
	if (!$card->title) error('Invalid title.');

	if ($cardType != 'v' && $cardType != 'l' && $cardType != 'fl' && ($cardType != 'f' || !$isLastCard)) {
		echo "Casting cost (ex: 4R, {4}{R}, 1RWU, {10}{WU}):\n";
		$cost = trim(fgets(STDIN));
		if (strpos($cost, '{') === false) {
			$newCost = '';
			for ($i = 0, $n = strlen($cost); $i < $n; $i++)
				$newCost .= '{' . $cost[$i] . '}';
			$cost = $newCost;
		}
		$card->cost = $cost;

		$colors = Card::getCostColors($cost);
		$colorCount = strlen($colors);
		if ($colorCount == 1)
			$card->color = $colors;
		else if ($colorCount > 1)
			$card->color = 'Gld';
		else if ($card->cost)
			$card->color = 'Art';
	}

	if ($cardType == 'v') {
		$card->color = 'Art';
		$card->set = 'VG';
	}

	if ($cardType == 'l' || ($cardType == 'fl' && !$isLastCard)) {
		$card->color = 'Lnd';
		echo "Mana color(s) land can produce (ex: W, R, C, A, RG, RGW, WUBRG):\n";
		$writer->titleToLandColors[strtolower($card->title)] = Card::getCostColors(trim(fgets(STDIN)));
		if (!$writer->titleToLandColors[strtolower($card->title)]) error('Invalid land mana color(s).');
	}

	if (($cardType != 'f' && $cardType != 'fl') || !$isLastCard) {
		echo "Art (URL or local file path):\n";
		$card->artFileName = trim(fgets(STDIN));
	}

	if ($cardType != 'v') {
		echo "Type (ex: Creature - Human):\n";
		$card->type = str_replace('-', '&#8211;', upperCaseWords(trim(fgets(STDIN))));

		if ($cardType != 'l' && $cardType != 'fl') {
			echo "Power/toughness (ex: 3/4):\n";
			$card->pt = trim(fgets(STDIN));
		}
	}

	echo "Legal text (ex: {T}: Add {G} to your mana pool. #(This is italic.)#):\n";
	$text = '';
	while (true) {
		$input = trim(fgets(STDIN));
		if ($input == '') break;
		if ($text) $text .= "\n";
		$text .= $input;
	}
	$text = str_replace('-', '&#8211;', $text);
	$card->legal = $text;

	if ($cardType != 'f' && $cardType != 'fl') {
		echo "Flavor text:\n";
		$text = '';
		while (true) {
			$input = trim(fgets(STDIN));
			if ($input == '') break;
			if ($text) $text .= "\n";
			$text .= $input;
		}
		$card->flavor = str_replace('-', '&#8212;', $text);
	}
	
	if ($cardType == 'v') {
		echo "Starting & max hand size (ex: +1, -3, +10):\n";
		$hand = trim(fgets(STDIN));
		if (substr($hand, 0, 1) != '+' && substr($hand, 0, 1) != '-') error('Invalid starting & max hand size.');

		echo "Starting life (ex: +5, -12, +0):\n";
		$life = trim(fgets(STDIN));
		if (substr($life, 0, 1) != '+' && substr($life, 0, 1) != '-') error('Invalid starting life.');

		$card->legal = "Hand $hand, Life $life\n" . $card->legal;
	}

	if (($cardType != 'f' && $cardType != 'fl') || !$isLastCard) {
		echo "Artist:\n";
		$card->artist = trim(fgets(STDIN));

		echo "Copyright (ex: (tm) & (c) 2006 Lizards on a Post, Inc. 42/175):\n";
		$card->copyright = trim(fgets(STDIN));
		$card->copyright = str_replace('(tm)', '&#8482;', $card->copyright);
		$card->copyright = str_replace('(c)', '&#169;', $card->copyright);
		if (!$card->copyright) $card->copyright = ' ';
	}

	if ($cardType != 'v' && (($cardType != 'f' && $cardType != 'fl') || $isLastCard) && ($cardType != 's' || $isLastCard)) {
		echo "Edition (ex: A, B, 7E, 9E, IN, RAV):\n";
		$card->set = strtoupper(trim(fgets(STDIN)));

		echo "Rarity (ex: R, U, C):\n";
		$card->rarity = strtoupper(trim(fgets(STDIN)));

		if ($card->rarity && !$card->set) $card->set = 'X';
	}

	return $card;
}
 public function render()
 {
     global $config;
     echo $this->card . '...';
     $card = $this->card;
     $settings = $this->getSettings();
     $frameDir = $this->getFrameDir($card->title, $card->set, $settings);
     $costColors = Card::getCostColors($card->cost);
     $useMulticolorFrame = strlen($costColors) > 1 && strpos($settings['card.multicolor.frames'], strval(strlen($costColors))) !== false || $card->isDualManaCost() && (strpos($settings['card.multicolor.frames'], strval(strlen($costColors))) !== false || strlen($costColors) == 2);
     switch ($frameDir) {
         case "timeshifted":
             $useMulticolorFrame = false;
             break;
         case "transform-day":
             $useMulticolorFrame = false;
             $pts = explode("|", $card->pt);
             $card->pt = $pts[0];
             break;
         case "transform-night":
             $useMulticolorFrame = false;
             break;
     }
     $canvas = imagecreatetruecolor(736, 1050);
     // Art image.
     if ($card->isEldrazi() && $card->isArtefact()) {
         $this->drawArt($canvas, $card->artFileName, 0, 0, 1050, 736, !$config['art.keep.aspect.ratio']);
     } else {
         $this->drawArt($canvas, $card->artFileName, $settings['art.top'], $settings['art.left'], $settings['art.bottom'], $settings['art.right'], !$config['art.keep.aspect.ratio']);
     }
     echo '.';
     // Background image, border image, and grey title/type image.
     $borderImage = null;
     $greyTitleAndTypeOverlay = null;
     if ($card->isLand()) {
         // Land frame.
         $landColors = @$this->writer->titleToLandColors[strtolower($card->title)];
         if ($settings['card.multicolor.fetch.land.frames']) {
             switch (strtolower($card->title)) {
                 case 'flooded strand':
                     $landColors = 'WU';
                     break;
                 case 'bloodstained mire':
                     $landColors = 'BR';
                     break;
                 case 'wooded foothills':
                     $landColors = 'RG';
                     break;
                 case 'polluted delta':
                     $landColors = 'UB';
                     break;
                 case 'windswept heath':
                     $landColors = 'GW';
                     break;
                 case 'flood plain':
                     $landColors = 'WU';
                     break;
                 case 'rocky tar pit':
                     $landColors = 'BR';
                     break;
                 case 'mountain valley':
                     $landColors = 'RG';
                     break;
                 case 'bad river':
                     $landColors = 'UB';
                     break;
                 case 'grasslands':
                     $landColors = 'GW';
                     break;
             }
         }
         switch (strtolower($card->title)) {
             case 'arid mesa':
                 $landColors = 'RW';
                 break;
             case 'marsh flats':
                 $landColors = 'WB';
                 break;
             case 'misty rainforest':
                 $landColors = 'GU';
                 break;
             case 'scalding tarn':
                 $landColors = 'UR';
                 break;
             case 'verdant catacombs':
                 $landColors = 'BG';
                 break;
         }
         if (!$landColors) {
             error('Land color missing for card: ' . $card->title);
         }
         if (strlen($landColors) > 1) {
             $useMulticolorLandFrame = strpos($settings['card.multicolor.land.frames'], strval(strlen($landColors))) !== false;
             if (!$useMulticolorLandFrame) {
                 $landColors = 'A';
             }
         }
         $bgImage = @imagecreatefrompng("images/eighth/{$frameDir}/land/{$landColors}.png");
         if (!$bgImage) {
             error("Background image not found for land color \"{$landColors}\": " . $card->title);
         }
         // Grey title/type image.
         if (strlen($landColors) >= 2 && $settings['card.multicolor.grey.title.and.type']) {
             $greyTitleAndTypeOverlay = @imagecreatefrompng("images/eighth/{$frameDir}/cards/C-overlay.png");
             if (!$greyTitleAndTypeOverlay) {
                 error('Image not found: C-overlay.png');
             }
         }
         // Green title/type image
         if (strtolower($card->title) == 'murmuring bosk') {
             $greyTitleAndTypeOverlay = @imagecreatefrompng("images/eighth/{$frameDir}/cards/G-overlay.png");
             if (!$greyTitleAndTypeOverlay) {
                 error('Image not found: G-overlay.png');
             }
         }
     } else {
         if ($card->isEldrazi() && $card->isArtefact()) {
             $bgImage = @imagecreatefrompng("images/eighth/{$frameDir}/cards/Eldrazi.png");
         } else {
             if ($card->isArtefact()) {
                 $bgImage = @imagecreatefrompng("images/eighth/{$frameDir}/cards/Art.png");
                 if (strpos($settings['card.artifact.color'], strval(strlen($costColors))) !== false) {
                     if (strlen($costColors) >= 2) {
                         $useMulticolorFrame = false;
                         $borderImage = @imagecreatefrompng("images/eighth/{$frameDir}/borders/{$costColors}.png");
                     } else {
                         $useMulticolorFrame = false;
                         $borderImage = @imagecreatefrompng("images/eighth/{$frameDir}/borders/{$card->color}.png");
                     }
                 } else {
                     if (strlen($costColors) >= 2 || $card->color == 'Gld') {
                         $useMulticolorFrame = false;
                         $borderImage = @imagecreatefrompng("images/eighth/{$frameDir}/borders/Gld.png");
                     }
                 }
             } else {
                 if ($useMulticolorFrame) {
                     // Multicolor frame.
                     $bgImage = @imagecreatefrompng("images/eighth/{$frameDir}/cards/{$costColors}.png");
                     if (!$bgImage) {
                         error("Background image not found for color: {$costColors}");
                     }
                     // Grey title/type image.
                     if ($settings['card.multicolor.grey.title.and.type']) {
                         $greyTitleAndTypeOverlay = @imagecreatefrompng("images/eighth/{$frameDir}/cards/C-overlay.png");
                         if (!$greyTitleAndTypeOverlay) {
                             error('Image not found: C-overlay.png');
                         }
                     }
                 } else {
                     // Mono color frame.
                     $bgImage = @imagecreatefrompng("images/eighth/{$frameDir}/cards/" . $card->color . '.png');
                     if (!$bgImage) {
                         error('Background image not found for color "' . $card->color . '" in frame dir: ' . $frameDir);
                     }
                     // Border image.
                     if (strlen($costColors) == 2 && $settings['card.multicolor.dual.borders']) {
                         $borderImage = @imagecreatefrompng("images/eighth/{$frameDir}/borders/{$costColors}.png");
                     }
                 }
             }
         }
     }
     imagecopy($canvas, $bgImage, 0, 0, 0, 0, 736, 1050);
     imagedestroy($bgImage);
     if ($borderImage) {
         imagecopy($canvas, $borderImage, 0, 0, 0, 0, 736, 1050);
         imagedestroy($borderImage);
     }
     if ($greyTitleAndTypeOverlay) {
         imagecopy($canvas, $greyTitleAndTypeOverlay, 0, 0, 0, 0, 736, 1050);
         imagedestroy($greyTitleAndTypeOverlay);
     }
     // Power / toughness.
     if ($card->pt) {
         if ($card->isEldrazi() && $card->isArtefact()) {
             $image = @imagecreatefrompng("images/eighth/{$frameDir}/pt/B.png");
         } else {
             if ($useMulticolorFrame) {
                 $image = @imagecreatefrompng("images/eighth/{$frameDir}/pt/" . substr($costColors, -1, 1) . '.png');
             } else {
                 $image = @imagecreatefrompng("images/eighth/{$frameDir}/pt/" . $card->color . '.png');
             }
         }
         if (!$image) {
             error("Power/toughness image not found for color: {$card->color}");
         }
         imagecopy($canvas, $image, 0, 1050 - 162, 0, 0, 736, 162);
         imagedestroy($image);
         $this->drawText($canvas, $settings['pt.center.x'], $settings['pt.center.y'], $settings['pt.width'], $card->pt, $this->font('pt'));
     }
     //Transform P/T
     if ($frameDir == "transform-day" && isset($pts[1])) {
         $this->drawText($canvas, $settings['pt.transform.center.x'], $settings['pt.transform.center.y'], $settings['pt.transform.width'], $pts[1], $this->font('pt.transform'));
     }
     // Casting cost.
     $costLeft = $this->drawCastingCost($canvas, $card->getCostSymbols(), $card->isDualManaCost() ? $settings['cost.top.dual'] : $settings['cost.top'], $settings['cost.right'], $settings['cost.size'], true);
     echo '.';
     // Set and rarity.
     if (!$card->isBasicLand() || $settings['card.basic.land.set.symbols']) {
         $rarityLeft = $this->drawRarity($canvas, $card->rarity, $card->set, $settings['rarity.right'], $settings['rarity.center.y'], $settings['rarity.height'], $settings['rarity.width'], false);
     } else {
         $rarityLeft = $settings['rarity.right'];
     }
     // Card title.
     $this->drawText($canvas, $settings['title.x'], $settings['title.y'], $costLeft - $settings['title.x'], $card->getDisplayTitle(), $this->font('title'));
     echo '.';
     // Type.
     if ($indicator = $this->getIndicator($card->title)) {
         $image = @imagecreatefrompng("images/symbols/indicators/" . $indicator . '.png');
         imagecopyresampled($canvas, $image, $settings['indicator.x'], $settings['indicator.y'], 0, 0, $settings['indicator.size'], $settings['indicator.size'], 300, 300);
         imagedestroy($image);
         $typex = $settings['type.indicator.x'];
     } else {
         $typex = $frameDir == "transform-night" && $card->isArtefact() ? $settings['type.art.x'] : $settings['type.x'];
     }
     $this->drawText($canvas, $typex, $settings['type.y'], $rarityLeft - $settings['type.x'], $card->type, $this->font('type'));
     // Guild sign.
     if ($card->set == "DIS" || $card->set == "GP" || $card->set == "GPT" || $card->set == "RAV" || $card->set == "RV") {
         if ($guild = $this->getGuild($card->title)) {
             list($image, $width, $height) = getPNG("images/eighth/guilds/{$guild}.png", "Guild image not found for: {$guild}");
             imagecopy($canvas, $image, 373 - $width / 2, 652, 0, 0, $width, $height);
             imagecopy($canvas, $image, 373 - $width / 2, 652, 0, 0, $width, $height);
             // Too much alpha, need to apply twice.
             imagedestroy($image);
         }
     }
     // Phyrexia/Mirran sign.
     if ($card->set == "SOM" || $card->set == "MBS" || $card->set == "NPH") {
         if ($phyrexia = $this->getPhyrexia($card->title)) {
             list($image, $width, $height) = getPNG("images/eighth/phyrexia/{$phyrexia}.png", "Phyrexia/Mirran image not found for: {$phyrexia}");
             imagecopy($canvas, $image, 373 - $width / 2, 652, 0, 0, $width, $height);
             imagecopy($canvas, $image, 373 - $width / 2, 652, 0, 0, $width, $height);
             // Too much alpha, need to apply twice.
             imagedestroy($image);
         }
     }
     // Promo overlay
     if ($card->promo && !$card->isBasicLand()) {
         list($image, $width, $height) = getPNG('images/promo/' . $card->promo . '.png', 'Promo overlay image not found for: ' . $card->promo);
         imagecopy($canvas, $image, 359 - $width / 2, 680, 0, 0, $width, $height);
         imagedestroy($image);
     }
     if ($card->isBasicLand() || $card->isLand() && $card->legal == '' && $card->flavor == '') {
         // Basic land symbol instead of legal text.
         list($image, $width, $height) = getPNG("images/symbols/land/{$landColors}.png", "Basic land image not found for: images/symbols/land/{$landColors}.png");
         imagecopy($canvas, $image, 373 - $width / 2, 660, 0, 0, $width, $height);
         imagedestroy($image);
     } else {
         if ($card->isLand() && strlen($landColors) == 2 && !$card->legal) {
             // Dual land symbol instead of legal text.
             if ($settings['card.dual.land.symbols'] == 1) {
                 // Single hybrid symbol.
                 list($image, $width, $height) = getPNG("images/symbols/land/{$landColors}.png", "Dual symbol image not found for: {$landColors}");
                 imagecopy($canvas, $image, 368 - $width / 2, 680, 0, 0, $width, $height);
                 imagedestroy($image);
             } else {
                 if ($settings['card.dual.land.symbols'] == 2) {
                     // One of each basic symbol.
                     $landColor = substr($landColors, 0, 1);
                     list($image, $width, $height) = getPNG("images/symbols/land/{$landColor}.png", 'Basic land image not found for: ' . $card->title);
                     imagecopy($canvas, $image, 217 - $width / 2, 660, 0, 0, $width, $height);
                     imagedestroy($image);
                     $landColor = substr($landColors, 1, 2);
                     list($image, $width, $height) = getPNG("images/symbols/land/{$landColor}.png", 'Basic land image not found for: ' . $card->title);
                     imagecopy($canvas, $image, 519 - $width / 2, 660, 0, 0, $width, $height);
                     imagedestroy($image);
                 }
             }
         } else {
             // Legal and flavor text.
             if (strlen($card->legal) < 40 && strpos($card->legal, "\n") === FALSE && $card->flavor == '') {
                 $this->drawText($canvas, ($settings['text.right'] + $settings['text.left']) / 2, ($settings['text.top'] + $settings['text.bottom']) / 2, null, $card->legal, $this->font('text', 'centerY:true centerX:true'));
             } else {
                 $heightAdjust = $card->pt ? $settings['text.pt.height.adjust'] : 0;
                 $this->drawLegalAndFlavorText($canvas, $settings['text.top'], $settings['text.left'], $settings['text.bottom'], $settings['text.right'], $card->legal, $card->flavor, $this->font('text'), $heightAdjust);
             }
         }
     }
     // Artist and copyright.
     // The artist color is white if the frame behind it is black.
     $footerColor = '0,0,0';
     if ($card->isLand()) {
         $footerColor = '255,255,255';
     } else {
         if (($costColors == 'B' || $card->color == 'B') && !$card->isArtefact()) {
             $footerColor = '255,255,255';
         } else {
             if ($card->isEldrazi() && $card->isArtefact()) {
                 $footerColor = '255,255,255';
             } else {
                 if ($useMulticolorFrame) {
                     // Only multicolor frames with a bottom left color of black should use a white footer.
                     if (strlen($costColors) <= 2 && substr($costColors, 0, 1) == 'B' || strlen($costColors) >= 3 && substr($costColors, 2, 1) == 'B') {
                         $footerColor = '255,255,255';
                     }
                 }
             }
         }
     }
     if ($card->artist) {
         if ($settings['card.artist.gears']) {
             $artistSymbol = '{gear}';
         } else {
             $artistSymbol = '{brush}';
         }
         $this->drawText($canvas, $settings['artist.x'], $settings['artist.y'], null, $artistSymbol . $card->artist, $this->font('artist', 'color:' . $footerColor));
     }
     if ($card->copyright) {
         $this->drawText($canvas, $settings['copyright.x'], $settings['copyright.y'], null, $card->copyright, $this->font('copyright', 'color:' . $footerColor));
     }
     echo "\n";
     return $canvas;
 }
Exemple #7
0
 public function __construct($mwsFileName)
 {
     $mwsFile = fopen_utf8($mwsFileName, 'rb');
     if (!$mwsFile) {
         error('Unable to open masterbase CSV file: ' . $mwsFileName);
     }
     echo "Processing MWS masterbase...";
     // windows-1252
     //$csv = new CSV(';', "\r\n", '"'); // Cell separator, row separator, value enclosure.
     //$csv->setContent(file_get_contents($mwsFileName, false , null)); // Parse the string content.
     //$rows = $csv->getArray();
     $i = 0;
     while (($row = fgetcsv($mwsFile, 6000, ';', '"')) !== FALSE) {
         //foreach($rows as $row){
         if ($i++ == 0) {
             continue;
         }
         //skip first line
         if ($i++ % 50 == 0) {
             echo '.';
         }
         // Extract.
         $title = (string) trim($row[0]);
         $set = (string) trim($row[1]);
         $color = (string) trim($row[4]);
         $type = (string) trim($row[6]);
         $p = (string) trim($row[8]);
         $t = (string) trim($row[9]);
         $flavor = (string) trim($row[10]);
         $rarity = (string) trim($row[11]);
         $cost = (string) trim($row[5]);
         $legal = trim($row[7]);
         $pic = (string) trim($row[2]);
         $artist = (string) trim($row[12]);
         $collectorNumber = (string) trim($row[13]);
         // Title.
         if ($set == 'VG') {
             $title = 'Avatar: ' . $title;
         }
         // Casting cost.
         $cost = $this->replaceDualManaSymbols($cost);
         $cost = $this->replacePhyrexiaSymbols($cost);
         $cost = preg_replace('/([0-9]+)/', '{\\1}', $cost);
         //
         $cost = preg_replace('/([WUBRGXYZ])/', '{\\1}', $cost);
         $cost = preg_replace('/{{([0-9XYZWUBRG])}{([WUBRG])}}/', '{\\1\\2}', $cost);
         $cost = preg_replace('/{([P]){([WUBRG])}}/', '{\\1\\2}', $cost);
         // Color.
         if ($color == 'Z/Z' || strpos($title, '/') !== FALSE && $p == "" && $t == "") {
             // Determine split card colors.
             $cost1 = substr($cost, 0, strpos($cost, '/'));
             $colors = Card::getCostColors($cost1);
             $color = strlen($colors) == 1 ? $colors : 'Gld';
             $color .= '/';
             $cost2 = substr($cost, strpos($cost, '/') + 1);
             $colors = Card::getCostColors($cost2);
             $color .= strlen($colors) == 1 ? $colors : 'Gld';
         }
         if (strpos($title, "/") !== FALSE && ($p != "" && $t != "" || $set == 'DKA' || $set == 'ISD')) {
             // flip cards fixes
             $title1 = substr($title, 0, strpos($title, '/'));
             $title2 = substr($title, strpos($title, '/') + 1);
             $title = $title1;
             $type1 = substr($type, 0, strpos($type, '/'));
             $type2 = substr($type, strpos($type, '/') + 1);
             $type = $type1;
             $pt = "";
             if (strpos($t, '|') !== FALSE) {
                 $t1 = substr($t, 0, strpos($t, '|'));
                 $pt = substr($t, strpos($t, '|') + 1);
                 $t = $t1;
             } else {
                 if (strpos($p, '|') !== FALSE) {
                     $p1 = substr($p, 0, strpos($p, '|'));
                     $pt = substr($p, strpos($p, '|') + 1) . '/' . $t;
                     $p = $p1;
                     $t = '';
                     if ($pt == '#/') {
                         //maybe need something more generic for dual planeswalkers later
                         $pt = '';
                         $p .= '#';
                     }
                 }
             }
             $insertPosition = strpos($legal, "//");
             $insertString = "\n" . $title2 . "\n" . $type2 . ($pt != "" ? "\n" . $pt : "");
             $legalTmp = substr_replace($legal, $insertString, $insertPosition + 2, 0);
             $legal = $legalTmp;
         }
         //php5 fixups
         $flavor = str_replace("�", '', $flavor);
         $flavor = iconv('windows-1250', 'utf-8', $flavor);
         $legal = iconv('windows-1250', 'utf-8', $legal);
         $artist = iconv('windows-1250', 'utf-8', $artist);
         //convert title and type just in case
         $title = iconv('windows-1250', 'utf-8', $title);
         $type = iconv('windows-1250', 'utf-8', $type);
         // Type.
         $type = str_replace(' - ', ' — ', $type);
         // Legal.
         $legal = $this->replaceDualManaSymbols($legal);
         $legal = $this->replacePhyrexiaSymbols($legal);
         $legal = preg_replace('/\\%([0-9]+)/', '{\\1}', $legal);
         $legal = preg_replace('/\\%([WUBRGTXYZ])/', '{\\1}', $legal);
         $legal = str_replace('%C', '{Q}', $legal);
         $legal = str_replace("<hr>", "-----", $legal);
         $flavor = str_replace("<hr>", "-----", $flavor);
         $legal = str_replace("//", "-----", $legal);
         $flavor = str_replace("//", "-----", $flavor);
         //card specific
         $legal = str_replace('El-Hajjaj', 'El-Hajjâj', $legal);
         $legal = str_replace('Junun', 'Junún', $legal);
         $legal = str_replace('Lim-Dul', 'Lim-Dûl', $legal);
         $legal = str_replace('Jotun', 'Jötun', $legal);
         $legal = str_replace('Ghazban', 'Ghazbán', $legal);
         $legal = str_replace('Ifh-Biff', 'Ifh-Bíff', $legal);
         $legal = str_replace('Juzam', 'Juzám', $legal);
         $legal = str_replace('Khabal', 'Khabál', $legal);
         $legal = str_replace('Marton', 'Márton', $legal);
         $legal = str_replace("Ma'ruf", "Ma'rûf", $legal);
         $legal = str_replace("Ma’ruf", "Ma’rûf", $legal);
         $legal = str_replace('Deja Vu', 'Déjà Vu', $legal);
         $legal = str_replace('Dandan', 'Dandân', $legal);
         $legal = str_replace('Bosium', 'Bösium', $legal);
         $legal = str_replace(' en-', ' #en#-', $legal);
         $legal = str_replace(' il-', ' #il#-', $legal);
         $legal = str_replace('Seance', 'Séance', $legal);
         $legal = preg_replace('/#([^#]+)# – /', '\\1 – ', $legal);
         // Remove italics from ability keywords.
         $legal = str_replace("\r\n-----\r\n", "\n-----\n", $legal);
         // Flip card separator.
         $legal = str_replace('Creature - ', 'Creature — ', $legal);
         $legal = str_replace(' upkeep - ', ' upkeep—', $legal);
         $legal = str_replace(' - ', ' — ', $legal);
         $legal = str_replace('AE', 'Æ', $legal);
         $legal = str_replace(".]", ".)", $legal);
         $legal = str_replace("\r\n", "\n", $legal);
         // Fix vanguard inconsistencies.
         if (preg_match('/Starting & Max[^\\+\\-]+([\\+\\-][0-9]+)[^\\+\\-]+([\\+\\-][0-9]+)/', $legal, $matches)) {
             $legal = 'Hand ' . $matches[1] . ', Life ' . $matches[2] . "\n" . substr($legal, 0, strpos($legal, ' Starting & Max'));
         }
         if (preg_match('/Hand Size[^\\+\\-]+([\\+\\-][0-9]+)[^\\+\\-]+([\\+\\-][0-9]+)\\.?/', $legal, $matches)) {
             $legal = 'Hand ' . $matches[1] . ', Life ' . $matches[2] . "\n" . substr($legal, 0, strpos($legal, 'Hand Size'));
         }
         $legal = trim($legal);
         // Flavor.
         $flavor = str_replace("'", '’', $flavor);
         // ' to ’
         $flavor = preg_replace('/"([^"]*)"/', '“\\1”', $flavor);
         // "text" to “text”
         $flavor = preg_replace("/(.*[^.]) '([^']*)'/", "\\1 ‘\\2’", $flavor);
         // 'text' to ‘text’
         $flavor = preg_replace('/(.*[^.]) ’(.*)’/', '\\1 ‘\\2’', $flavor);
         // ’text’ to ‘text’
         $flavor = str_replace('”’', '’”', $flavor);
         // ”’ to ’”
         $flavor = str_replace('‘”', '”‘', $flavor);
         // ‘” to ”‘
         $flavor = str_replace('“’', '“‘', $flavor);
         // “’ to “‘
         $flavor = str_replace(',’', '’,', $flavor);
         // ,’ to ’,
         $flavor = preg_replace("/\r\n- (.?)/", "\n—\\1", $flavor);
         // - to —
         $flavor = preg_replace("/\r\n#- (.?)/", "\n#—\\1", $flavor);
         $flavor = preg_replace("/ - /", "—", $flavor);
         $flavor = str_replace('AE', 'Æ', $flavor);
         $flavor = str_replace("\r\n", "\n", $flavor);
         $flavor = str_replace('"', '”', $flavor);
         // " to ”
         // Store.
         $card = new Card();
         $card->title = $title;
         $card->set = $set;
         $card->color = $color;
         $card->type = $type;
         $card->pt = $p != "" && $t != "" ? $p . '/' . $t : (preg_match('/%([0-9]+)#/', $p, $matches) ? "/{$matches['1']}" : '');
         $card->flavor = $flavor;
         $card->rarity = $rarity;
         $card->cost = $cost;
         $card->legal = $legal;
         $card->pic = $pic;
         $card->artist = $artist;
         $card->collectorNumber = $collectorNumber;
         $this->cards[] = $card;
     }
     // Compute total cards in each set.
     $setToCollectorNumbers = array();
     foreach ($this->cards as $card) {
         // Only count cards with collector numbers.
         if (!$card->collectorNumber) {
             continue;
         }
         // Don't count the same collector number twice.
         if (!@$setToCollectorNumbers[$card->set]) {
             $setToCollectorNumbers[$card->set] = array();
         }
         if (@$setToCollectorNumbers[$card->set][$card->collectorNumber]) {
             continue;
         }
         $setToCollectorNumbers[$card->set][$card->collectorNumber] = true;
     }
     foreach ($this->cards as $card) {
         if (!$card->collectorNumber) {
             continue;
         }
         // Try hardcoded value first.
         $cardsInSet = MasterBase::getTotalCardsInSet($card->set);
         // Then try computed vallue.
         if (!$cardsInSet && @$setToCollectorNumbers[$card->set]) {
             $cardsInSet = count($setToCollectorNumbers[$card->set]);
         }
         if (!$cardsInSet) {
             continue;
         }
         $card->collectorNumber .= '/' . $cardsInSet;
     }
 }
Exemple #8
0
	public function render () {
		global $config;

		echo $this->card . '...';
		$card = $this->card;

		$settings = $this->getSettings();
		$costColors = Card::getCostColors($card->cost);
		$canvas = imagecreatetruecolor(736, 1050);

		// Art image.
		$this->drawArt($canvas, $card->artFileName, $settings['art.top'], $settings['art.left'], $settings['art.bottom'], $settings['art.right'], !$config['art.keep.aspect.ratio']);

		echo '.';

		// Background image.
		if ($card->isLand()) {
			// Land frame.
			$landColors = @$this->writer->titleToLandColors[strtolower($card->title)];
			$notBasicFrame = '';
			if ($settings['card.multicolor.fetch.land.frames']) {
				switch (strtolower($card->title)) {
				case 'flooded strand': $landColors = 'WU'; break;
				case 'bloodstained mire': $landColors = 'BR'; break;
				case 'wooded foothills': $landColors = 'RG'; break;
				case 'polluted delta': $landColors = 'UB'; break;
				case 'windswept heath': $landColors = 'GW'; break;
				case 'flood plain': $landColors = 'WU'; break;
				case 'rocky tar pit': $landColors = 'BR'; break;
				case 'mountain valley': $landColors = 'RG'; break;
				case 'bad river': $landColors = 'UB'; break;
				case 'grasslands': $landColors = 'GW'; break;
				}
			}
			if (!$landColors) error('Land color missing for card: ' . $card->title);
			if (strlen($landColors) > 1) {
				$useMulticolorLandFrame = strpos($settings['card.multicolor.land.frames'], strval(strlen($landColors))) !== false;
				if (strlen($landColors) > 2 || !$useMulticolorLandFrame) $landColors = 'A';
			}
			else if(!$card->isBasicLand() && $landColors != 'A' && $landColors != 'C')
				$notBasicFrame = 'C';
			$bgImage = @imagecreatefrompng("images/preEighth/land/$notBasicFrame$landColors.png");
			if (!$bgImage) error("Background image not found for land color \"$notBasicFrame$landColors\": " . $card->title);
		} else {
			// Mono color frame.
			$bgImage = @imagecreatefrompng('images/preEighth/cards/' . $card->color . '.png');
			if (!$bgImage) error('Background image not found for mono color: ' . $card->color);
		}
		imagecopy($canvas, $bgImage, 0, 0, 0, 0, 736, 1050);

		// Power / toughness.
		if ($card->pt) $this->drawText($canvas, $settings['pt.center.x'], $settings['pt.center.y'], $settings['pt.width'], $card->pt, $this->font('pt'));

		// Casting cost.
		$costLeft = $this->drawCastingCost($canvas, $card->getCostSymbols(), $settings['cost.top'], $settings['cost.right'], $settings['cost.size']);

		echo '.';

		// Set and rarity.
		if (!$card->isBasicLand() || $settings['card.basic.land.set.symbols']) {
			$rarityMiddle = $settings['rarity.center.y'];
			if ($card->isLand()) $rarityMiddle += 2; // Rarity on pre8th lands is slightly lower.
			$rarityLeft = $this->drawRarity($canvas, $card->rarity, $card->set, $settings['rarity.right'], $rarityMiddle, $settings['rarity.height'], $settings['rarity.width'], true, $settings['card.rarity.fallback']);
		} else
			$rarityLeft = $settings['rarity.right'];

		// Tombstone sign.
		if ($settings['card.tombstone']) {
			if (strpos($card->legal, 'Flashback') !=false || strpos($card->type, 'Incarnation') !=false || $card->title == 'Riftstone Portal' || $card->title == 'Ichorid') {
				list($image, $width, $height) = getPNG('images/preEighth/tombstone.png', 'Tombstone image not found.');
				imagecopy($canvas, $image, $settings["tombstone.left"], $settings["tombstone.top"], 0, 0, $width, $height);
			}
		}

		// Card title.
		$this->drawText($canvas, $settings['title.x'], $settings['title.y'], $costLeft - $settings['title.x'], $card->getDisplayTitle(false), $this->font('title'));

		echo '.';

		// Type.
		$typeBaseline = $settings['type.y'];
		if ($card->isLand()) $typeBaseline += 2; // Type on pre8th lands is slightly lower.
		$this->drawText($canvas, $settings['type.x'], $typeBaseline, $rarityLeft - $settings['type.x'], $card->type, $this->font('type'));

		if ($card->isBasicLand()) {
			// Basic land symbol instead of legal text.
			list($image, $width, $height) = getPNG("images/symbols/land/$landColors.png", "Basic land image not found for: images/symbols/land/$landColors.png");
			imagecopy($canvas, $image, 373 - ($width / 2), 640, 0, 0, $width, $height);
		} else if ($card->isLand() && strlen($landColors) == 2 && !$card->legal) {
			// Dual land symbol instead of legal text.
			if ($settings['card.dual.land.symbols'] == 1) {
				// Single hybrid symbol.
				list($image, $width, $height) = getPNG("images/symbols/land/$landColors.png", "Dual symbol image not found for: $landColors");
				imagecopy($canvas, $image, 368 - ($width / 2), 667, 0, 0, $width, $height);
			} else if ($settings['card.dual.land.symbols'] == 2) {
				// One of each basic symbol.
				$landColor = substr($landColors, 0, 1);
				list($image, $width, $height) = getPNG("images/symbols/land/$landColor.png", 'Basic land image not found for: ' . $card->title);
				imagecopy($canvas, $image, 217 - ($width / 2), 640, 0, 0, $width, $height);

				$landColor = substr($landColors, 1, 2);
				list($image, $width, $height) = getPNG("images/symbols/land/$landColor.png", 'Basic land image not found for: ' . $card->title);
				imagecopy($canvas, $image, 519 - ($width / 2), 640, 0, 0, $width, $height);
			}
		} else {
			// Legal and flavor text.
			$this->drawLegalAndFlavorText($canvas, $settings['text.top'], $settings['text.left'], $settings['text.bottom'], $settings['text.right'], $card->legal, $card->flavor, $this->font('text'));
		}

		// Artist and copyright.
		if ($card->artist) $this->drawText($canvas, $settings['artist.x'], $settings['artist.y'], null, 'Illus. ' . $card->artist, $this->font('artist'));
		if ($card->copyright) {
			$copyrightColor = '255,255,255';
			if ($card->color == 'W') $copyrightColor = '0,0,0';
			$this->drawText($canvas, $settings['copyright.x'], $settings['copyright.y'], null, $card->copyright, $this->font('copyright', 'color:' . $copyrightColor));
		}

		echo "\n";
		return $canvas;
	}
 public function render()
 {
     global $config;
     echo $this->card . '...';
     $card = $this->card;
     $settings = $this->getSettings();
     $costColors = Card::getCostColors($card->cost);
     $white = '255,255,255';
     $useMulticolorFrame = strlen($costColors) == 2;
     $canvas = imagecreatetruecolor(736, 1050);
     // Art image.
     $this->drawArt($canvas, $card->artFileName, $settings['art.top'], $settings['art.left'], $settings['art.bottom'], $settings['art.right'], !$config['art.keep.aspect.ratio']);
     echo '.';
     // Background image.
     $borderImage = null;
     $greyTitleAndTypeOverlay = null;
     if ($card->isArtefact()) {
         $bgImage = @imagecreatefrompng('images/planeswalker/regular/cards/Art4.png');
     } else {
         if ($useMulticolorFrame || $card->isDualManaCost()) {
             // Multicolor frame.
             if ($settings['card.multicolor.gold.frame']) {
                 $bgImage = @imagecreatefrompng("images/planeswalker/regular/cards/Gld{$costColors4}.png");
             } else {
                 $bgImage = @imagecreatefrompng("images/planeswalker/regular/cards/{$costColors4}.png");
             }
             if (!$bgImage) {
                 error("Background image not found for color: {$costColors}");
             }
         } else {
             // Mono color frame.
             $bgImage = @imagecreatefrompng('images/planeswalker/regular/cards/' . $card->color . '4.png');
             if (!$bgImage) {
                 error('Background image not found for color "' . $card->color . '"');
             }
         }
     }
     imagecopy($canvas, $bgImage, 0, 0, 0, 0, 736, 1050);
     imagedestroy($bgImage);
     // Loyalty
     if ($card->pt) {
         $image = @imagecreatefrompng('images/planeswalker/loyalty/LoyaltyBegin.png');
         if (!$image) {
             error("Loyalty image not found");
         }
         imagecopy($canvas, $image, 605, 940, 0, 0, 127, 82);
         imagedestroy($image);
         $card->pt = (string) str_replace('/', '', $card->pt);
         $this->drawText($canvas, $settings['loyalty.starting.center.x'], $settings['loyalty.starting.center.y'], $settings['loyalty.starting.width'], $card->pt, $this->font('loyalty.starting', 'color:' . $white));
     }
     // Casting cost.
     $costLeft = $this->drawCastingCost($canvas, $card->getCostSymbols(), $card->isDualManaCost() ? $settings['cost.top.dual'] : $settings['cost.top'], $settings['cost.right'], $settings['cost.size'], true);
     echo '.';
     // Set and rarity.
     $rarityLeft = $this->drawRarity($canvas, $card->rarity, $card->set, $settings['rarity.right'], $settings['rarity.center.y'], $settings['rarity.height'], $settings['rarity.width'], false);
     // Card title.
     $this->drawText($canvas, $settings['title.x'], $settings['title.y'], $costLeft - $settings['title.x'], $card->getDisplayTitle(), $this->font('title'));
     echo '.';
     // Type.
     $this->drawText($canvas, $settings['type.x'], $settings['type.y'], $rarityLeft - $settings['type.x'], $card->type, $this->font('type'));
     // Legal text.
     if (!preg_match_all('/(\\+|-)?([0-9XYZ]+): (.*?)(?=$|[-|\\+]?[0-9XYZ]+:)/s', $card->legal, $matches)) {
         error('Missing legality change from legal text: ' . $card->title);
     }
     //print_r($matches);
     $logaltyImage = null;
     $loyalty = array();
     //1
     $this->loyaltyIcon($matches[1][0], 1, $logaltyImage, $loyalty);
     imagecopy($canvas, $logaltyImage, $loyalty['x'], $loyalty['y'], 0, 0, $loyalty['w'], $loyalty['h']);
     imagedestroy($logaltyImage);
     $this->drawText($canvas, $settings['loyalty.1.center.x'], $settings['loyalty.1.center.y'], $settings['loyalty.1.center.width'], preg_replace('/([+|-])/', '{\\1}', $matches[1][0]) . $matches[2][0], $this->font('loyalty.change', 'color:' . $white));
     $this->drawLegalAndFlavorText($canvas, $settings['text.1.top'], $settings['text.1.left'], $settings['text.1.bottom'], $settings['text.1.right'], $matches[3][0], null, $this->font('text'), 0);
     //2
     $this->loyaltyIcon($matches[1][1], 2, $logaltyImage, $loyalty);
     imagecopy($canvas, $logaltyImage, $loyalty['x'], $loyalty['y'], 0, 0, $loyalty['w'], $loyalty['h']);
     imagedestroy($logaltyImage);
     $this->drawText($canvas, $settings['loyalty.2.center.x'], $settings['loyalty.2.center.y'], $settings['loyalty.2.center.width'], preg_replace('/([+|-])/', '{\\1}', $matches[1][1]) . $matches[2][1], $this->font('loyalty.change', 'color:' . $white));
     $this->drawLegalAndFlavorText($canvas, $settings['text.2.top'], $settings['text.2.left'], $settings['text.2.bottom'], $settings['text.2.right'], $matches[3][1], null, $this->font('text'), 0);
     //3
     $this->loyaltyIcon($matches[1][2], 3, $logaltyImage, $loyalty);
     imagecopy($canvas, $logaltyImage, $loyalty['x'], $loyalty['y'], 0, 0, $loyalty['w'], $loyalty['h']);
     imagedestroy($logaltyImage);
     $this->drawText($canvas, $settings['loyalty.3.center.x'], $settings['loyalty.3.center.y'], $settings['loyalty.3.center.width'], preg_replace('/([+|-])/', '{\\1}', $matches[1][2]) . $matches[2][2], $this->font('loyalty.change', 'color:' . $white));
     $this->drawLegalAndFlavorText($canvas, $settings['text.3.top'], $settings['text.3.left'], $settings['text.3.bottom'], $settings['text.3.right'], $matches[3][2], null, $this->font('text'), 10);
     //4
     $this->loyaltyIcon($matches[1][3], 4, $logaltyImage, $loyalty);
     imagecopy($canvas, $logaltyImage, $loyalty['x'], $loyalty['y'], 0, 0, $loyalty['w'], $loyalty['h']);
     imagedestroy($logaltyImage);
     $this->drawText($canvas, $settings['loyalty.4.center.x'], $settings['loyalty.4.center.y'], $settings['loyalty.4.center.width'], preg_replace('/([+|-])/', '{\\1}', $matches[1][3]) . $matches[2][3], $this->font('loyalty.change', 'color:' . $white));
     $this->drawLegalAndFlavorText($canvas, $settings['text.4.top'], $settings['text.4.left'], $settings['text.4.bottom'], $settings['text.4.right'], $matches[3][3], null, $this->font('text'), 10);
     // Artist and copyright.
     // The artist color is white if the frame behind it is black.
     $footerColor = '255,255,255';
     if ($card->artist) {
         if ($settings['card.artist.gears']) {
             $artistSymbol = '{gear}';
         } else {
             $artistSymbol = '{brush}';
         }
         $this->drawText($canvas, $settings['artist.x'], $settings['artist.y'], $settings['artist.width'], $artistSymbol . $card->artist, $this->font('artist', 'color:' . $footerColor));
     }
     if ($card->copyright) {
         $this->drawText($canvas, $settings['copyright.x'], $settings['copyright.y'], null, $card->copyright, $this->font('copyright', 'color:' . $footerColor));
     }
     //Art overlay
     $overlayFileName = preg_replace('/(.*)\\.(jpg|png)/i', '$1-overlay.png', $card->artFileName);
     if (file_exists($overlayFileName)) {
         $this->drawArt($canvas, $overlayFileName, $settings['art.top'], $settings['art.left'], $settings['art.bottom'], $settings['art.right'], !$config['art.keep.aspect.ratio']);
     }
     echo "\n";
     return $canvas;
 }