コード例 #1
0
        //cut point by height
        $h_point = ($height - $height_new) / 2;
        //copy image
        imagecopyresampled($dst_img, $src_img, 0, 0, 0, $h_point, $max_width, $max_height, $width, $height_new);
    } else {
        //cut point by width
        $w_point = ($width - $width_new) / 2;
        imagecopyresampled($dst_img, $src_img, 0, 0, $w_point, 0, $max_width, $max_height, $width_new, $height);
    }
    $ext = strtolower(pathinfo($_GET['url'], PATHINFO_EXTENSION));
    if ($ext == "jpeg") {
        imagejpeg($dst_img);
    }
    if ($ext == "jpg") {
        imagejpeg($dst_img);
    }
    if ($ext == "png") {
        imagepng($dst_img);
    }
    if ($ext == "gif") {
        imagepng($dst_img);
    }
}
//usage example
$sizze = 150;
if (isset($_GET["size"])) {
    $sizze = intval($_GET["size"]);
}
resize_crop_image($sizze, $sizze, $_GET["url"]);
?>
 
コード例 #2
0
ファイル: test4.php プロジェクト: yehchge/resize
            break;
        default:
            return false;
            break;
    }
    $dst_img = imagecreatetruecolor($max_width, $max_height);
    $src_img = $image_create($source_file);
    $width_new = $height * $max_width / $max_height;
    $height_new = $width * $max_height / $max_width;
    //if the new width is greater than the actual width of the image, then the height is too large and the rest cut off, or vice versa
    if ($width_new > $width) {
        //cut point by height
        $h_point = ($height - $height_new) / 2;
        //copy image
        imagecopyresampled($dst_img, $src_img, 0, 0, 0, $h_point, $max_width, $max_height, $width, $height_new);
    } else {
        //cut point by width
        $w_point = ($width - $width_new) / 2;
        imagecopyresampled($dst_img, $src_img, 0, 0, $w_point, 0, $max_width, $max_height, $width_new, $height);
    }
    $image($dst_img, $dst_dir, $quality);
    if ($dst_img) {
        imagedestroy($dst_img);
    }
    if ($src_img) {
        imagedestroy($src_img);
    }
}
//usage example
resize_crop_image(500, 500, "image.jpg", "test4.jpg");
コード例 #3
0
            if (url_exists($url)) {
                file_put_contents($raw, file_get_contents($url));
            } else {
                $url = "http://img.youtube.com/vi/" . $idyoutube . "/hqdefault.jpg";
                if (url_exists($url)) {
                    file_put_contents($raw, file_get_contents($url));
                } else {
                    $url = "http://img.youtube.com/vi/" . $idyoutube . "/mqdefault.jpg";
                    if (url_exists($url)) {
                        file_put_contents($raw, file_get_contents($url));
                    }
                }
            }
        }
    } elseif (strpos($video->video_url, 'vimeo') !== false) {
        $idviemo = trim(extractIdVimeo($video->video_url));
        if (!empty($idviemo)) {
            $hash = unserialize(file_get_contents("http://vimeo.com/api/v2/video/{$idviemo}.php"));
            file_put_contents($raw, file_get_contents($hash[0]['thumbnail_large']));
        }
    } elseif (strpos($video->video_url, 'dailymotion') !== false) {
        $iddailymotion = trim(extractDailymotion($video->video_url));
        if (!empty($iddailymotion)) {
            $hash = json_decode(file_get_contents("https://api.dailymotion.com/video/{$iddailymotion}?fields=thumbnail_large_url"));
            file_put_contents($raw, file_get_contents($hash->thumbnail_large_url));
        }
    }
    if (file_exists($raw)) {
        resize_crop_image(THUMB_WIDTH, THUMB_HEIGHT, $raw, $img);
    }
}