/** * This function resizes an image, with preserving its proportions (or aspect ratio). * @author Ivan Tcholakov, MAY-2009. * @param int $image System path or URL of the image * @param int $target_width Targeted width * @param int $target_height Targeted height * @return array Calculated new width and height */ function api_resize_image($image, $target_width, $target_height) { $image_properties = api_getimagesize($image); return api_calculate_image_size($image_properties['width'], $image_properties['height'], $target_width, $target_height); }
//clean memory imagedestroy($crop); } //end !exist thumbnail //show thumbnail and link $one_image_thumbnail_file = '.thumbs/.' . $one_image_file; //get path thumbnail $doc_url = $path && $path !== '/' ? $path . '/' . $one_image_thumbnail_file : $path . $one_image_thumbnail_file; $image_tag[] = '<img src="download.php?doc_url=' . $doc_url . '" border="0" title="' . $one_image_file . '">'; } else { //if images aren't support by gd (not gif, jpg, jpeg, png) if ($imagetype == "bmp") { // use getimagesize instead api_getimagesize($image); becasuse api_getimagesize doesn't support bmp files. Put here for each show, only for a few bmp files isn't heavy $original_image_size = getimagesize($image); if ($max_thumbnail_width < $original_image_size[0] || $max_thumbnail_height < $original_image_size[1]) { $thumbnail_size = api_calculate_image_size($original_image_size[0], $original_image_size[1], $max_thumbnail_width, $max_thumbnail_height); //don't use resize_image because doesn't run with bmp files $image_height = $thumbnail_size['height']; $image_width = $thumbnail_size['width']; } else { $image_height = $original_image_size[0]; $image_width = $original_image_size[1]; } } else { //example for svg files,... $image_width = $max_thumbnail_width; $image_height = $max_thumbnail_height; } $doc_url = $path && $path !== '/' ? $path . '/' . $one_image_file : $path . $one_image_file; $image_tag[] = '<img src="download.php?doc_url=' . $doc_url . '" border="0" width="' . $image_width . '" height="' . $image_height . '" title="' . $one_image_file . '">'; }
//run each once we view thumbnails is too heavy, then need move into !file_exists($image_thumbnail, and only run when haven't the thumbnail switch ($imagetype) { case 'gif': $source_img = imagecreatefromgif($image); break; case 'jpg': $source_img = imagecreatefromjpeg($image); break; case 'jpeg': $source_img = imagecreatefromjpeg($image); break; case 'png': $source_img = imagecreatefrompng($image); break; } $new_thumbnail_size = api_calculate_image_size($original_image_size['width'], $original_image_size['height'], $max_thumbnail_width, $max_thumbnail_height); if ($max_thumbnail_width > $original_image_size['width'] && $max_thumbnail_height > $original_image_size['height']) { $new_thumbnail_size['width'] = $original_image_size['width']; $new_thumbnail_size['height'] = $original_image_size['height']; } $crop = imagecreatetruecolor($new_thumbnail_size['width'], $new_thumbnail_size['height']); // preserve transparency if ($imagetype == "png") { imagesavealpha($crop, true); $color = imagecolorallocatealpha($crop, 0x0, 0x0, 0x0, 127); imagefill($crop, 0, 0, $color); } if ($imagetype == "gif") { $transindex = imagecolortransparent($source_img); $palletsize = imagecolorstotal($source_img); //GIF89a for transparent and anim (first clip), either GIF87a