elkidogz Posted August 3, 2007 Share Posted August 3, 2007 ok, I'm pretty raw to PHP, but basically what i am doing here is making a thumbnail of an image that was uploaded. the codes here: function createAThumb( $pathToImages, $pathToThumbs, $fname, $thumbWidth ) { // open the directory $dir = opendir( $pathToImages ); // parse path for the extension $info = pathinfo($pathToImages . $fname); // continue only if this is a JPEG image if ( strtolower($info['extension']) == 'jpg' ) { //echo "Creating thumbnail for {$fname} <br />"; // load image and get image size $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" ); $width = imagesx( $img ); $height = imagesy( $img ); // calculate thumbnail size $new_width = $thumbWidth; $new_height = floor( $height * ( $thumbWidth / $width ) ); // create a new temporary image $tmp_img = imagecreatetruecolor( $new_width, $new_height ); // copy and resize old image into new image imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height ); // save thumbnail into a file imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" ); } // close the directory closedir( $dir ); } where i am getting messed up is the $fname it's getting over wrote by the $info = pathinfo($pathToImages . $fname); line and i need that to make sure it's a jpg for the image to be resized. what should i try Link to comment https://forums.phpfreaks.com/topic/63251-help-with-my-function-to-make-a-thumbnail/ Share on other sites More sharing options...
teng84 Posted August 4, 2007 Share Posted August 4, 2007 i dont know how you get the file or the name of the file but if can get this pic.jpg(sample) then you can do something like this sample $x='teng.jpg'; $y=explode('.',$x); $jpg=($y[count($y)-1]) ; the result will be jpg Link to comment https://forums.phpfreaks.com/topic/63251-help-with-my-function-to-make-a-thumbnail/#findComment-315284 Share on other sites More sharing options...
Fadion Posted August 4, 2007 Share Posted August 4, 2007 the same about getting the extension but in a different approach $file = 'pic.jpg'; $ext = substr(strrchr($file, '.'), 1); echo $ext; it will print 'jpg' Link to comment https://forums.phpfreaks.com/topic/63251-help-with-my-function-to-make-a-thumbnail/#findComment-315293 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.