コード例 #1
0
 /**
  * Output the image with the logos of each artist
  */
 public function show()
 {
     if (count($this->artists) == 0) {
         throw new Exception("Missing some informations (artists).");
     }
     $totalHeight = array(self::$marginTop, self::$marginTop);
     $listImageRessources = array(array(), array());
     $forcedWidth = self::$width / 2 - self::$seperation / 2;
     foreach ($this->artists as $name) {
         if (count($listImageRessources[0]) + count($listImageRessources[1]) == $this->nbArtists) {
             break;
         }
         $a = Artists::getArtistByName($name);
         if ($a != null) {
             $image = Artists::imageFromArtist($a);
             if (isset($image)) {
                 $i = $totalHeight[1] < $totalHeight[0] ? 1 : 0;
                 $x = imagesx($image);
                 $y = imagesy($image);
                 $newHeight = floor($y * $forcedWidth / $x);
                 $totalHeight[$i] += $newHeight + self::$seperation;
                 array_push($listImageRessources[$i], $image);
             }
         }
     }
     $container = imagecreatetruecolor(self::$width, max($totalHeight));
     //Some colors needed
     $colWhite = imagecolorallocate($container, 255, 255, 255);
     //Background color
     imagefilledrectangle($container, 0, 0, self::$width, max($totalHeight), $colWhite);
     $currentHeight = array(self::$marginTop, self::$marginTop);
     for ($l = 0; $l < count($listImageRessources); $l++) {
         $list = $listImageRessources[$l];
         foreach ($list as $image) {
             $x = imagesx($image);
             $y = imagesy($image);
             $newHeight = floor($y * $forcedWidth / $x);
             $resized = imagecreatetruecolor($forcedWidth, $newHeight);
             imagecopyresampled($resized, $image, 0, 0, 0, 0, $forcedWidth, $newHeight, $x, $y);
             imagecopymerge($container, $resized, ($forcedWidth + self::$seperation) * $l, $currentHeight[$l], 0, 0, $forcedWidth, $newHeight, 100);
             //echo $currentHeight[$l] . "-";
             $currentHeight[$l] += $newHeight + self::$seperation;
         }
     }
     ImageUtil::applyFilter($container, $this->color);
     imagepng($container);
 }
コード例 #2
0
 /**
  * Output the image with the logos of each artist
  */
 public function show()
 {
     if (count($this->artists) == 0) {
         throw new Exception("Missing some informations (artists).");
     }
     $totalHeight = 0;
     $listImageRessources = array();
     foreach ($this->artists as $name) {
         if (count($listImageRessources) == $this->nbArtists) {
             break;
         }
         $a = Artists::getArtistByName($name);
         if ($a != null) {
             $image = Artists::imageFromArtist($a);
             if (isset($image)) {
                 $totalHeight += imagesy($image) + self::$seperation;
                 array_push($listImageRessources, $image);
             }
         }
     }
     //echo $totalHeight;
     $totalHeight += self::$marginTop;
     $container = imagecreatetruecolor(self::$width, $totalHeight);
     //Some colors needed
     $colWhite = imagecolorallocate($container, 255, 255, 255);
     //Background color
     imagefilledrectangle($container, 0, 0, self::$width, $totalHeight, $colWhite);
     $expectWidth = self::$width - 2 * self::$marginSide;
     $currentHeight = self::$marginTop;
     foreach ($listImageRessources as $image) {
         $widthImg = imagesx($image);
         //echo $this->width."-2 * ".self::$marginSide);
         //echo $widthImg."--".$expectWidth."<br/>";
         imagecopymerge($container, $image, self::$marginSide + ($widthImg < $expectWidth ? ($expectWidth - $widthImg) * 0.5 : 0), $currentHeight, 0, 0, imagesx($image), imagesy($image), 100);
         $currentHeight += imagesy($image) + self::$seperation;
     }
     ImageUtil::applyFilter($container, $this->color);
     imagepng($container);
 }