JesseElser Posted December 20, 2015 Share Posted December 20, 2015 I'm getting an error and no matter how many people look at the code no one can figure out why. The error I'm getting is: Parse error: syntax error, unexpected '$ratio_orig' (T_VARIABLE) in /home/jollyrogerpcs/public_html/img/gallery/thumbnail.php on line 23 The code is: // thumb width $square = 150; $large = 200; $small = 100; ////////////////////////////////////////////////////////////////////////////////// square if( isset($_GET["img"]) && ( $_GET["type"] == "square" || $_GET["type"] == "" ) ){ // thumb size $thumb_width = $square; $thumb_height = $square; // align $align = $_GET["align"]; // image source $imgSrc = $_GET["img"]; $imgExt = substr($imgSrc,-3); // image extension if($imgExt == "jpg"){ $myImage = imagecreatefromjpeg($imgSrc); } if($imgExt == "gif"){ $myImage = imagecreatefromgif($imgSrc); } if($imgExt == "png"){ $myImage = imagecreatefrompng($imgSrc); } // getting the image dimensions list($width_orig, $height_orig) = getimagesize($imgSrc); // ratio $ratio_orig = $width_orig/$height_orig; // landscape or portrait? if ($thumb_width/$thumb_height > $ratio_orig) { $new_height = $thumb_width/$ratio_orig; $new_width = $thumb_width; } else { $new_width = $thumb_height*$ratio_orig; $new_height = $thumb_height; } // middle $x_mid = $new_width/2; $y_mid = $new_height/2; // create new image $process = imagecreatetruecolor(round($new_width), round($new_height)); imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); $thumb = imagecreatetruecolor($thumb_width, $thumb_height); // alignment if($align == ""){ imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height); } if($align == "top"){ imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), 0, $thumb_width, $thumb_height, $thumb_width, $thumb_height); } if($align == "bottom"){ imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($new_height-$thumb_height), $thumb_width, $thumb_height, $thumb_width, $thumb_height); } if($align == "left"){ imagecopyresampled($thumb, $process, 0, 0, 0, ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height); } if($align == "right"){ imagecopyresampled($thumb, $process, 0, 0, ($new_width-$thumb_width), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height); } imagedestroy($process); imagedestroy($myImage); if($imgExt == "jpg"){ imagejpeg($thumb, null, 100); } if($imgExt == "gif"){ imagegif($thumb); } if($imgExt == "png"){ imagepng($thumb, null, 9); } } // normal if(isset($_GET["img"]) && ($_GET["type"] == "large" || $_GET["type"] == "small" ) ){ if( $_GET["type"] == "large" ){ $thumb_width = $large; } if( $_GET["type"] == "small" ){ $thumb_width = $small; } // image source $imgSrc = $_GET["img"]; $imgExt = substr($imgSrc,-3); // image extension if($imgExt == "jpg"){ $myImage = imagecreatefromjpeg($imgSrc); } if($imgExt == "gif"){ $myImage = imagecreatefromgif($imgSrc); } if($imgExt == "png"){ $myImage = imagecreatefrompng($imgSrc); } //getting the image dimensions list($width_orig, $height_orig) = getimagesize($imgSrc); // ratio $ratio_orig = $width_orig/$height_orig; $thumb_height = $thumb_width/$ratio_orig; // new dimensions $new_width = $thumb_width; $new_height = $thumb_height; // middle $x_mid = $new_width/2; $y_mid = $new_height/2; // create new image $process = imagecreatetruecolor(round($new_width), round($new_height)); imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig); $thumb = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height); if($imgExt == "jpg"){ imagejpeg($thumb, null, 100); } if($imgExt == "gif"){ imagegif($thumb); } if($imgExt == "png"){ imagepng($thumb, null, 9); } } Every line has the required semicolons. All brackets are properly closed. I have zero clue why that error even exists and I had this posted on another site and no one could figure it out. If it helps the script is from http://1stwebmagazine.com/generate-thumbnail-on-the-fly-with-php Quote Link to comment https://forums.phpfreaks.com/topic/299907-php-listing-non-existent-error/ Share on other sites More sharing options...
benanamen Posted December 20, 2015 Share Posted December 20, 2015 (edited) * Edited December 20, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/299907-php-listing-non-existent-error/#findComment-1528319 Share on other sites More sharing options...
JesseElser Posted December 20, 2015 Author Share Posted December 20, 2015 * Whats the "*" for? Quote Link to comment https://forums.phpfreaks.com/topic/299907-php-listing-non-existent-error/#findComment-1528321 Share on other sites More sharing options...
ginerjm Posted December 20, 2015 Share Posted December 20, 2015 Would have been nice if you pointed out where line 23 was. Quote Link to comment https://forums.phpfreaks.com/topic/299907-php-listing-non-existent-error/#findComment-1528323 Share on other sites More sharing options...
mac_gyver Posted December 21, 2015 Share Posted December 21, 2015 the code as posted above doesn't produce that error. it's likely that something about how it was published, with the highlighting, and how you copied it into your file or what you used as an editor got some encoded characters or the edits you did introduced a curly/smart-quote instead of a straight-quote. i would copy/paste the above into a completely new file and try it. Quote Link to comment https://forums.phpfreaks.com/topic/299907-php-listing-non-existent-error/#findComment-1528324 Share on other sites More sharing options...
JesseElser Posted December 21, 2015 Author Share Posted December 21, 2015 Would have been nice if you pointed out where line 23 was. Is there not a way to edit? Quote Link to comment https://forums.phpfreaks.com/topic/299907-php-listing-non-existent-error/#findComment-1528326 Share on other sites More sharing options...
ginerjm Posted December 21, 2015 Share Posted December 21, 2015 You have some extra hidden chars at the end of this line right before $ratio_orig is ref'ed list($width_orig, $height_orig) = getimagesize($imgSrc); Quote Link to comment https://forums.phpfreaks.com/topic/299907-php-listing-non-existent-error/#findComment-1528327 Share on other sites More sharing options...
JesseElser Posted December 21, 2015 Author Share Posted December 21, 2015 You have some extra hidden chars at the end of this line right before $ratio_orig is ref'ed list($width_orig, $height_orig) = getimagesize($imgSrc); Removed all of the extra characters that show as blank spaces. Error code is now changing lines which i assume is more special characters. Do you have any suggestions on how to easily find any of these special chars? Quote Link to comment https://forums.phpfreaks.com/topic/299907-php-listing-non-existent-error/#findComment-1528329 Share on other sites More sharing options...
Solution ginerjm Posted December 21, 2015 Solution Share Posted December 21, 2015 Highlight the entire script and look for colored areas with no visible chars in them Quote Link to comment https://forums.phpfreaks.com/topic/299907-php-listing-non-existent-error/#findComment-1528332 Share on other sites More sharing options...
JesseElser Posted December 21, 2015 Author Share Posted December 21, 2015 Highlight the entire script and look for colored areas with no visible chars in them Got them all removed and now there are no errors. Oddly enough it's a blank page now and not making thumbnails still but it's progress lol. Quote Link to comment https://forums.phpfreaks.com/topic/299907-php-listing-non-existent-error/#findComment-1528335 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.