1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
if ( ! function_exists('create_square_thumb')) { function create_square_thumb($img,$dest) { $seg = explode('.',$img); $thumbType = 'jpg'; $thumbSize = 300; $thumbPath = $dest; $thumbQuality = 100; $last_index = count($seg); $last_index--; if($seg[$last_index]=='jpg' || $seg[$last_index]=='JPG' || $seg[$last_index]=='jpeg') { if (!$full = imagecreatefromjpeg($img)) { return 'error'; } } else if($seg[$last_index]=='png') { if (!$full = imagecreatefrompng($img)) { return 'error'; } } else if($seg[$last_index]=='gif') { if (!$full = imagecreatefromgif($img)) { return 'error'; } } $width = imagesx($full); $height = imagesy($full); /* work out the smaller version, setting the shortest side to the size of the thumb, constraining height/wight */ if ($height > $width) { $divisor = $width / $thumbSize; } else { $divisor = $height / $thumbSize; } $resizedWidth = ceil($width / $divisor); $resizedHeight = ceil($height / $divisor); /* work out center point */ $thumbx = floor(($resizedWidth - $thumbSize) / 2); $thumby = floor(($resizedHeight - $thumbSize) / 2); /* create the small smaller version, then crop it centrally to create the thumbnail */ $resized = imagecreatetruecolor($resizedWidth, $resizedHeight); $thumb = imagecreatetruecolor($thumbSize, $thumbSize); imagealphablending( $resized, false ); imagesavealpha( $resized, true ); imagealphablending( $thumb, false ); imagesavealpha( $thumb, true ); imagecopyresized($resized, $full, 0, 0, 0, 0, $resizedWidth, $resizedHeight, $width, $height); imagecopyresized($thumb, $resized, 0, 0, $thumbx, $thumby, $thumbSize, $thumbSize, $thumbSize, $thumbSize); $name = name_from_url($img); imagejpeg($thumb, $thumbPath.str_replace('_large.jpg', '_thumb.jpg', $name), $thumbQuality); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
if ( ! function_exists('create_rectangle_thumb')) { function create_rectangle_thumb($img,$dest) { $seg = explode('.',$img); $thumbType = 'jpg'; $thumbSize = 300; $thumbWidth = 300; $thumbHeight = 226; $thumbPath = $dest; $thumbQuality = 100; $last_index = count($seg); $last_index--; if($seg[$last_index]=='jpg' || $seg[$last_index]=='JPG' || $seg[$last_index]=='jpeg') { if (!$full = imagecreatefromjpeg($img)) { return 'error'; } } else if($seg[$last_index]=='png') { if (!$full = imagecreatefrompng($img)) { return 'error'; } } else if($seg[$last_index]=='gif') { if (!$full = imagecreatefromgif($img)) { return 'error'; } } $width = imagesx($full); $height = imagesy($full); # work out the smaller version, setting the shortest side to the size of the thumb, constraining height/wight if ($height > $width) { $divisor = $width / $thumbHeight; } else { $divisor = $height / $thumbWidth; } $resizedWidth = ceil($width / $divisor); $resizedHeight = ceil($height / $divisor); # work out center point $thumbx = floor(($resizedWidth - $thumbWidth) / 2); $thumby = floor(($resizedHeight - $thumbHeight) / 2); /* create the small smaller version, then crop it centrally to create the thumbnail */ $resized = imagecreatetruecolor($resizedWidth, $resizedHeight); $thumb = imagecreatetruecolor($thumbWidth, $thumbHeight); imagealphablending( $resized, false ); imagesavealpha( $resized, true ); imagealphablending( $thumb, false ); imagesavealpha( $thumb, true ); imagecopyresized($resized, $full, 0, 0, 0, 0, $resizedWidth, $resizedHeight, $width, $height); imagecopyresized($thumb, $resized, 0, 0, $thumbx, $thumby, $thumbSize, $thumbSize, $thumbSize, $thumbSize); $name = name_from_url($img); imagejpeg($thumb, $thumbPath.str_replace('_large.jpg', '_thumb.jpg', $name), $thumbQuality); } } |