0

I am trying to run the below code in W3shcools phptryit page but I get this error:

PHP Fatal error: Uncaught Error: Call to undefined function imagecreatefromjpeg() in /home/LPmJMe/prog.php:26 Stack trace: #0 /home/LPmJMe/prog.php(35): resize_image('data:image/jpeg...', 100, 100) #1 {main} thrown in /home/LPmJMe/prog.php on line 26

function resize_image($file, $w, $h, $crop=FALSE) {
    list($width, $height) = getimagesize($file); 
    $r = $width / $height;
        if ($crop) {
            if ($width > $height) {
                $width = ceil($width-($width*abs($r-$w/$h)));
                 
            } else {
                $height = ceil($height-($height*abs($r-$w/$h)));
            }
            $newwidth = $w;
            $newheight = $h;
        } else {
            if ($w/$h > $r) {
                $newwidth = $h*$r;
                $newheight = $h;
            } else {
                $newheight = $w/$r;
                $newwidth = $w;
            }
            }
        $src = imagecreatefromjpeg($file);
        $dst = imagecreatetruecolor($newwidth, $newheight);
        imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
        echo $newheight;
    $filename= basename($file,".jpg");
    $file=$filename.'-'.$w.'x'.$h.'jpg';
}
$w=100;
$h=100;
resize_image($file, $w, $h);
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46
kmboon
  • 21
  • 1
  • Is the GD image extension enabled in your php ini file? Do any of the other `image` functions work? – Professor Abronsius Aug 11 '22 at 07:03
  • Searching for "Call to undefined function imagecreatefromjpeg()" here on stackoverflow yields at least half a dozen questions with answers - please do a little bit of research the next time - if you did, and you have a different problem, include this information in your question. – Tom Regner Aug 11 '22 at 07:14
  • @ProfessorAbronsius Actually I have no php.ini file. I am running this on w3Schools practice place. – kmboon Aug 14 '22 at 10:29
  • well it seems then that W3Schools do not allow you to use the GD library so there is nothing you can do about that. – Professor Abronsius Aug 14 '22 at 10:40
  • @ProfessorAbronsius So there is no inline code I write to fix this? – kmboon Aug 15 '22 at 05:15
  • I do not believe so. Do you not have your own development webserver? – Professor Abronsius Aug 15 '22 at 06:21

0 Answers0