private function loadSource(PhutilSprite $sprite) { $file = $sprite->getSourceFile(); if (empty($this->sources[$file])) { $data = Filesystem::readFile($file); $this->sources[$file] = imagecreatefromstring($data); } return $this->sources[$file]; }
private function loadSource(PhutilSprite $sprite, $scale) { $file = $sprite->getSourceFile($scale); if (empty($this->sources[$file])) { $data = Filesystem::readFile($file); $image = imagecreatefromstring($data); $this->sources[$file] = array('image' => $image, 'x' => imagesx($image), 'y' => imagesy($image)); } $s_w = $sprite->getSourceW() * $scale; $i_w = $this->sources[$file]['x']; if ($s_w > $i_w) { throw new Exception(pht("Sprite source for '%s' is too small (expected width %d, found %d).", $file, $s_w, $i_w)); } $s_h = $sprite->getSourceH() * $scale; $i_h = $this->sources[$file]['y']; if ($s_h > $i_h) { throw new Exception(pht("Sprite source for '%s' is too small (expected height %d, found %d).", $file, $s_h, $i_h)); } return $this->sources[$file]['image']; }