douweng7308 2015-12-20 21:11
浏览 46

预写的PHP脚本显示错误 - 无法找出错误存在的原因

I'm using a pre-written script found at 1st Web Magazine - Generate Thumbnail On The Fly.

I copied the script over to my server, but it's giving me the following error: Parse error: syntax error, unexpected '$ratio_orig' (T_VARIABLE) in /storage/emulated/legacy/www/jollyroger/jollyroger/img/gallery_temp/thumbnail.php on line 23

I've went through the code and I cannot spot any actual errors. Everything seems to be in order.

Could someone take a look at this code and tell me if I am overlooking something? From what I can gather it seems that something in the list() function is throwing off the variables.

This is the code actually in my file:

<?php
// 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); }
}
?>

Even this line in my editor is highlighted red which indicates an error, but since the variable is triggering a php error this one has not shown up in any logs yet. Looking over this line I cannot spot anything wrong at all.

if(isset($_GET["img"]) && ($_GET["type"] == "large" || $_GET["type"] == "small" ) ){

I copied the code direct from the website so I'm at a loss as to why it is not working. As I said I've looked it over and everything seems to be in order, so I'm at a complete loss.

Also this script is in the same directory as my image files. My test url looks like so: http://localhost:8080/jollyroger/jollyroger/img/gallery_temp/thumbnail.php?img=1959523_1501438810115481_7515978806557307096_n.jpg

  • 写回答

1条回答 默认 最新

  • duanchun1852 2015-12-20 21:40
    关注

    I think I found something.

    you have the following line:

    list($width_orig, $height_orig) = getimagesize($imgSrc);  
    

    which seems really weird to me. You are equalling a function to a function which might cause the error on the next line.

    If that's not the problem then either you forgot a ; or you tried to access the variable before you set its value somewhere.

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算