- ベストアンサー
PHPのimagecreatefromjpeg()
お世話になります。 今自分が作っている、画像のサムネイルを発生させるプログラムで、上記タイトルのimagecreatefromjpeg()関数が未定義であるとのメッセージが以下のように出てきます。 Call to undefined function PhpSolutions\Image\imagecreatefromjpeg() この関数はPHPのビルトインですので、名前空間も無関係のはずですし、未定義という事の意味が分かりません。 以下にクラスThumbnail の定義と、それを使うアプリケーション create_thumb.php を添付します。ここに入り切らない部分は捕捉に添付しておきます。どこが原因でこうなるのかをご指摘いただける方がいらっしゃいましたら、どうかよろしくご教授ください。 <?php namespace PhpSolutions\Image; class Thumbnail{ protected $original; protected $originalheight; protected $originalwidth; protected $basename; protected $maxSize = 120; protected $destination; protected $suffix = '_thb'; protected $messages = []; protected $imageType; public function __construct($image, $destination, $maxSize = 120, $suffix='_thb'){ if(is_file($image) && is_readable($image)){ $details = getimagesize($image); }else{ throw new \Exception("cannot open $image"); } if(!is_array($details)){ throw new \Exception("$image doesn't appear to be an image."); }else { if($details[0] == 0){ // width of image throw new \Exception("cannot determin the size of $image."); } // check the MIME type if(!$this->checkType($details['mime'])){ // mime type of image throw new \Exception("cannot process that type of file."); } $this->original = $image; $this->originalwidth = $details[0]; $this->originalheight = $details[1]; $this->basename = pathinfo($image, PATHINFO_FILENAME); $this->setDestination($destination); $this->setMaxSize($maxSize); $this->setSuffix($suffix); } }// construct public function create(){ $ratio = $this->calculateRatio($this->originalwidth, $this->originalheight, $this->maxSize); $thumbwidth = round($this->originalwidth * $ratio); $thumbheight = round($this->originalheight * $ratio); $resource = $this->createImageResource(); $thumb = imagecreatetruecolor($thumbwidth. $thumbheight); //create thumbnail imagecopyresampled($thumb, $resource, 0,0,0,0, $thumbwidth, $thumbheight,$this->originalwidth, $this->originalheight); $newname = $this->basename.$this->suffix; switch ($this->imageType){ case 'jpeg': $newname .= '.jpg'; $success = imagejpeg($thumb, $this->destination, $newname); break; case 'png': $newname .= '.png'; $success = imagepng($thumb, $this->destination, $newname); break; case 'gif': $newname .= '.gif'; $success = imagegif($thumb, $this->destination, $newname); break; case 'webp': $newname .= '.webp'; $success = imagewebp($thumb, $this->destination, $newname); break; } if($success){ $this->message[] = "$newname created successfully."; }else{ $this->message[] = "Couldn't create thumbnail for basename($this->original)"; } imagedestroy($resource); imagedestroy($thumb); }
- みんなの回答 (3)
- 専門家の回答
お礼