waynew Posted September 20, 2008 Share Posted September 20, 2008 For some reason, if the width of the image is largely bigger than the height, the thumbnail ends up being a 70 x 70 black image. function cropImage($nw, $nh, $source, $stype, $dest) { $size = getimagesize($source); $w = $size[0]; $h = $size[1]; switch($stype) { case '.gif': $simg = imagecreatefromgif($source); break; case '.jpg': $simg = imagecreatefromjpeg($source); break; case '.jpeg': $simg = imagecreatefromjpeg($source); break; } $dimg = imagecreatetruecolor($nw, $nh); $wm = $w/$nw; $hm = $h/$nh; $h_height = $nh/2; $w_height = $nw/2; if($w> $h) { $adjusted_width = $w / $hm; $half_width = $adjusted_width / 2; $int_width = $half_width - $w_height; imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h); } elseif(($w <$h) || ($w == $h)) { $adjusted_height = $h / $wm; $half_height = $adjusted_height / 2; $int_height = $half_height - $h_height; imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h); } else { imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h); } imagejpeg($dimg,$dest,100); } Link to comment https://forums.phpfreaks.com/topic/125056-thumbnail-function-working-funny/ Share on other sites More sharing options...
waynew Posted September 20, 2008 Author Share Posted September 20, 2008 Bump for great justice. Link to comment https://forums.phpfreaks.com/topic/125056-thumbnail-function-working-funny/#findComment-646400 Share on other sites More sharing options...
JasonLewis Posted September 20, 2008 Share Posted September 20, 2008 With this: -$int_width Are you trying to inverse the sign? If so, make it this: $int_width*-1 But I'm just guessing because I don't really know what numbers to put where to try and make sense of it. Link to comment https://forums.phpfreaks.com/topic/125056-thumbnail-function-working-funny/#findComment-646423 Share on other sites More sharing options...
corbin Posted September 20, 2008 Share Posted September 20, 2008 -1*a = -a In fact, -1*a would be simplified to -a by 99% of the world x.x. It's entirely valid in PHP to do -$var. Hrmmm, the third param for imagecopyresampled() is dst_x. Why would that be negative? That doesn't make sense to me. If I have a 70x70 grid, with 0,0 being in the top left corner, and 70,70 being in the bottom right (like the top right quadrant of a Cartesian coordinate plane [iE normal graph]), for x,y if x is negative, then as long as x is negative, it won't be shown. So, if you have -a as your new x, the area shown would be 70-a (ignoring y's). So, to put things simply, the negative is probably what is screwing things up. Are you sure you really want the number to be negative? for bool imagecopyresampled ( resource $dst_image , resource $src_image , int $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h ) shouldn't you be doing something like: imagecopyresampled(dst_image, src_image, 0, 0, 0, 0, 70, 70, src_w, src_h); ? Link to comment https://forums.phpfreaks.com/topic/125056-thumbnail-function-working-funny/#findComment-646452 Share on other sites More sharing options...
JasonLewis Posted September 20, 2008 Share Posted September 20, 2008 -1*a = -a In fact, -1*a would be simplified to -a by 99% of the world x.x. It's entirely valid in PHP to do -$var. I'm not the brightest of the bunch. I've always done -1*a Link to comment https://forums.phpfreaks.com/topic/125056-thumbnail-function-working-funny/#findComment-646455 Share on other sites More sharing options...
corbin Posted September 20, 2008 Share Posted September 20, 2008 Eh what ever works ;p. Link to comment https://forums.phpfreaks.com/topic/125056-thumbnail-function-working-funny/#findComment-646473 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.