Example #1
0
function get_thumbnail($src_image, $thumbnail_width, $thumbnail_height)
{
    if (file_exists($src_image != 'images/' ? $src_image : '')) {
        $image_name = explode('/', $src_image);
        $image_name = explode('.', end($image_name));
        $folderName = public_path("animethumb/" . $thumbnail_width . "x" . $thumbnail_height . "/");
        if (!file_exists($folderName)) {
            mkdir($folderName);
        }
        $dest_image = "animethumb/" . $thumbnail_width . "x" . $thumbnail_height . "/" . $image_name[0] . ".jpg";
        if (!file_exists(public_path($dest_image))) {
            resize_crop($src_image, public_path($dest_image), $thumbnail_width, $thumbnail_height);
            return $src_image;
        }
        return $dest_image;
    } else {
        return '';
    }
}
Example #2
0
<?php

$src_image = $_GET['src'];
$thumbnail_width = $_GET['w'];
$thumbnail_width = $_GET['h'];
$dest_image = "animethumb/" . $_GET['w'] . "x" . $_GET['h'] . "/";
echo resize_crop($src_image, $dest_image, $thumbnail_width, $thumbnail_height);
function resize_crop($src_image, $dest_image, $thumbnail_width, $thumbnail_height, $jpg_quality = 100)
{
    // Get dimensions of existing image
    $image = getimagesize($src_image);
    // Check for valid dimensions
    if ($image[0] <= 0 || $image[1] <= 0) {
        return false;
    }
    //image MIME-type
    $image['format'] = strtolower(preg_replace('/^.*?\\//', '', $image['mime']));
    // Import image
    switch ($image['format']) {
        case 'jpg':
        case 'jpeg':
            $image_data = imagecreatefromjpeg($src_image);
            break;
        case 'png':
            $image_data = imagecreatefrompng($src_image);
            break;
        case 'gif':
            $image_data = imagecreatefromgif($src_image);
            break;
        default:
            // Unsupported format