PHP - Limitations And Imagecopyresampled Vs Imagecopyresized
Similar TutorialsThis code is taken from the book Learning Php Mysql & javascript. It converts an image into a thumbnail 100 by 100 and works fine in chrome but in IE8 it does not resize PNG images but saves them at original size. I have spent a day searching the internet for answers and even tried joining the books forum but had problems logging into it! If anyone knows why PNG images are not getting resized in IE8 I would be deeply grateful. Code: [Select] <?php // rnprofile.php include_once 'rnheader.php'; if (!isset($_SESSION['user'])) die("<br /><br />You need to login to view this page"); $user = $_SESSION['user']; echo "<h3>Edit your Profile</h3>"; if (isset($_POST['text'])) { $text = sanitizeString($_POST['text']); $text = preg_replace('/\s\s+/', ' ', $text); $query = "SELECT * FROM rnprofiles WHERE user='$user'"; if (mysql_num_rows(queryMysql($query))) { queryMysql("UPDATE rnprofiles SET text='$text' where user='$user'"); } else { $query = "INSERT INTO rnprofiles VALUES('$user', '$text')"; queryMysql($query); } } else { $query = "SELECT * FROM rnprofiles WHERE user='$user'"; $result = queryMysql($query); if (mysql_num_rows($result)) { $row = mysql_fetch_row($result); $text = stripslashes($row[1]); } else $text = ""; } $text = stripslashes(preg_replace('/\s\s+/', ' ', $text)); if (isset($_FILES['image']['name'])) { $saveto = "$user.jpg"; move_uploaded_file($_FILES['image']['tmp_name'], $saveto); $typeok = TRUE; switch($_FILES['image']['type']) { case "image/gif": $src = imagecreatefromgif($saveto); break; case "image/jpeg": // Both regular and progressive jpegs case "image/pjpeg": $src = imagecreatefromjpeg($saveto); break; case "image/png": $src = imagecreatefrompng($saveto); break; default: $typeok = FALSE; break; } if ($typeok) { list($w, $h) = getimagesize($saveto); $max = 100; $tw = $w; $th = $h; if ($w > $h && $max < $w) { $th = $max / $w * $h; $tw = $max; } elseif ($h > $w && $max < $h) { $tw = $max / $h * $w; $th = $max; } elseif ($max < $w) { $tw = $th = $max; } $tmp = imagecreatetruecolor($tw, $th)or die('Cannot Initialize new GD image stream'); imagecopyresampled($tmp, $src, 0, 0, 0, 0, $tw, $th, $w, $h); imageconvolution($tmp, array( // Sharpen image array(-1, -1, -1), array(-1, 16, -1), array(-1, -1, -1) ), 8, 0); imagejpeg($tmp, $saveto); imagedestroy($tmp); imagedestroy($src); } } showProfile($user); echo <<<_END <form method='post' action='rnprofile.php' enctype='multipart/form-data'> Enter or edit your details and/or upload an image:<br /> <textarea name='text' cols='40' rows='3'>$text</textarea><br /> Image: <input type='file' name='image' size='14' maxlength='32' /> <input type='submit' value='Save Profile' /> </pre></form> _END; ?> Thanks Gary Hi, i am wanting to implement a post restriction on the forum im building where a new user can only post 10 posts per day and create 2 topics per day. I have thought about the process but have become stuck. I am fine for checking if they have reached their post count for the day(just a simple +1 to the table when they post then query it before posting) but how would i reset the counter after the day is up? i have also done the bit that defines how long ago they registered. So if a user registered less than 1 week ago they are only permitted 10 posts and 2 topics per day. After the day ends they can post 10 more posts and 2 more topics(numbers are examples only). Then when they pass 1 week registered they can do anything. I just dont know how to reset the counter at the end of the day. This is my example code so far: $timeslot = (strtotime("-1 week")); $reg_date = (strtotime($posts_info->user_regdate)); if ($reg_date <= $timeslot) { THEY CAN DO ANYTHING } else { if $todays_post_count == 10) { THEY CANT POST } else { THEY CAN POST } Proportionally scale image - imagecopyresampled() This is part of a function I have to upload images and create thumbnails from the stored image - '$stored_image' Code: [Select] $src_image = imagecreatefromjpeg($stored_image); // $src_width = imagesx($src_image); $src_height = imagesy($src_image); $new_width = 85; $new_height = 85; // if($src_width > $src_height){ $thumb_w = $new_width; $thumb_h = $src_height*($new_height/$src_width); } if($src_width < $src_height){ $thumb_w = $src_width*($new_width/$src_height); $thumb_h = $new_height; } if($src_width == $src_height){ $thumb_w = $new_width; $thumb_h = $new_height; } // $thumb = imagecreatetruecolor($thumb_w, $thumb_h); imagecopyresampled($thumb, $src_image,0,0,0,0,$thumb_w, $thumb_h, $src_width, $src_height); imagejpeg($thumb, $stored_thumb, 100); imagedestroy($src_image); imagedestroy($thumb); }else{ The images are different size and orientations, landscape and portrait. The thumbnails need to have the same height so I need to proportionally scale the images How can I proportionally scale images so the thumbnails have the same height I'm really stuck here so any help would be greatly appreciated. so I have an array with a bunch of photos, and I'm trying to create a thumbnail of each to display on a page with a link to the full sized image but I'm getting the error in the subject title... if I just display the images in the array without trying to resize them it works fine... can anyone clue me into why this isn't working please. echo ("<a href='" . $img['file'] . "'>"); $new_width = (floor($img['size'][0] * ".25")); $new_height = (floor($img['size'][1] * ".25")); $tmp_img = imagecreatetruecolor($new_width, $new_height); imagecopyresized($tmp_img, $img['file'], 0, 0, 0, 0, $new_width, $new_height, $img['size'][0], $img['size'][1]); echo ("<img src='" . $tmp_img . " . $img['size'][3] , "' alt=''><br>\n"); echo basename($img['file']); echo "</a><br>\n"; Below is my image upload and resize script. The issue I am running into is when an image is wider than 800px (i'm not even sure how much wider, i just know that an image that is 800px wide will upload, but larger ones won't). Anyway, is there a "dimension limit" on images when using "imagecopyresized"? Thank you for your time? Code: [Select] $uploaddir3 = "/my/server/path/coname/images/"; $thumbDirectory3 = "/my/server/path/test"; $thumbWidth3 = "640"; $target_encoding3 = "ISO-8859-1"; echo '<pre>'; if(count($_FILES) > 0) { $arrfile3 = pos($_FILES); $uploadfile3 = $uploaddir3 . iconv("UTF-8", $target_encoding3,basename(strtoupper($arrfile3['name']))); if (move_uploaded_file($arrfile3['tmp_name'], $uploadfile3)) echo "File is valid, and was successfully uploaded.\n"; $imageName3 = basename(strtoupper($arrfile3['name'])); function createThumbnail3($uploaddir3, $imageName3, $thumbDirectory3, $thumbWidth3) { $srcImg3 = imagecreatefromjpeg("$uploaddir3/$imageName3"); $origWidth3 = imagesx($srcImg3); $origHeight3 = imagesy($srcImg3); $ratio3 = $thumbWidth3 / $origWidth3; $thumbHeight3 = $origHeight3 * $ratio3; $thumbImg3 = imagecreatetruecolor($thumbWidth3, $thumbHeight3); imagecopyresized($thumbImg3, $srcImg3, 0, 0, 0, 0, $thumbWidth3, $thumbHeight3, $origWidth3, $origHeight3); imagejpeg($thumbImg3, "$thumbDirectory3/$imageName3"); } createThumbnail3("/my/server/path", "$imageName3", "/my/server/path/coname/images/test", $thumbWidth3); } else { } |