Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does he method imagecreatefromjpeg($src) return false in my method?
    text
    copied!<p>I am new to php and I am trying to make thumbnails </p> <p>$src is the path to the image $thumbWidth is the desired width $imageName is not important it is needed to be passed to a function that generates the html code for the thumbnail.</p> <p>the problem is on line 174 which I commented out if the image is a jpeg file the function returns false and then $source_image is false can anyone explain why?</p> <p>here is my method:</p> <pre><code> function makeThumb( $src, $thumbWidth, $imageName ) { $count = 0; $len = strlen($src); $indexlen = $len - 1; $sourceArray = str_split($src); for($i = $indexlen; $i &gt; -1; $i--) { if($sourceArray[$i] == '.') { $count = $count + 1; if($count == 1) { $hold = $i; } } } $ending = substr($src, $hold, $len); if($ending === '.gif') { $type = '.gif'; $source_image = imagecreatefromgif($src); } if($ending === '.jpeg' || $ending === '.pjpeg' || $ending === '.jpg') { $type = '.jpg'; $source_image = imagecreatefromjpeg($src); } if($ending === '.png') { $type = '.png'; $source_image = imagecreatefrompng($src); } else { //throw new Exception('This file is not in JPG, GIF, or PNG format!'); $type = null; } /* read the source image */ if($ending = null) { return null; } $width = imagesx($src); $height = imagesy($src); $newWidth = $thumbWidth; /* find the "desired height" of this thumbnail, relative to the desired width */ $newHeight = floor($height * ($newWidth / $width)); /* create a new, "virtual" image */ $tempImg = imagecreatetruecolor($desired_width, $desired_height); $pic = formatImage($tempImg, $imageName); return $pic; /* copy source image at a resized size */ //imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height); /* create the physical thumbnail image to its destination */ //imagejpeg($virtual_image, $dest); </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload