Example #1
0
 private function doFaceShot(Character $char, $img)
 {
     if (!$char->isCropFaceShot()) {
         // nothing do to, image already in correct format
         return $img;
     }
     $png = imagecreatefromstring($img);
     $w = imagesx($png);
     $h = imagesy($png);
     // create new WxW image for face
     $out = imagecreatetruecolor($w, $w);
     $bg = imagecolorallocatealpha($out, 0, 0, 0, 127);
     imagefill($out, 0, 0, $bg);
     imagesavealpha($out, true);
     $top = max(0, $h / 2 - $w / 2);
     imagecopyresampled($out, $png, 0, 0, 0, $top, $w, $w, $w, $w);
     ob_start();
     imagepng($out, null, 9);
     $result = ob_get_clean();
     imagedestroy($png);
     imagedestroy($out);
     return $result;
 }
Example #2
0
 private function doFaceShot(Character $char, $img)
 {
     switch ($char->getRace()) {
         case TPeople::FYROS:
             $crop = [0 => [143, 157], 1 => [149, 180]];
             break;
         case TPeople::TRYKER:
             $crop = [0 => [143, 191], 1 => [148, 207]];
             break;
         case TPeople::MATIS:
             $crop = [0 => [144, 138], 1 => [148, 170]];
             break;
         case TPeople::ZORAI:
             $crop = [0 => [143, 109], 1 => [149, 122]];
             break;
         default:
             // should not reach here
             return $img;
     }
     $gender = $char->getGender();
     list($cx, $cy) = $crop[$gender];
     $x = $cx - 50;
     $y = $cy - 50;
     $w = 100;
     $h = 100;
     if ($char->isCropFaceShot()) {
         // WxW box
         $out = imagecreatetruecolor($this->width, $this->width);
         $dstw = $this->width;
         $dsth = $this->width;
     } else {
         // portrait
         $out = imagecreatetruecolor($this->width, $this->height);
         $dstw = $this->width;
         $dsth = $this->height;
         $y -= $h / 2;
         $h += $h;
     }
     $bg = imagecolorallocatealpha($out, 0, 0, 0, 127);
     imagefill($out, 0, 0, $bg);
     imagesavealpha($out, true);
     imagecopyresampled($out, $img, 0, 0, $x, $y, $dstw, $dsth, $w, $h);
     imagedestroy($img);
     return $out;
 }