const IMAGE_HANDLERS = [
    IMAGETYPE_JPEG => [
        'load' => 'imagecreatefromjpeg',
        'save' => 'imagejpeg',
        'quality' => 100
    ],
    IMAGETYPE_PNG => [
        'load' => 'imagecreatefrompng',
        'save' => 'imagepng',
        'quality' => 2
    ],
    IMAGETYPE_GIF => [
        'load' => 'imagecreatefromgif',
        'save' => 'imagegif',
        'quality' => 1
    ]
];
/**
 * @param $src - geçerli bir dosya yeri
 * @param $dest - geçerli bir dosya hedefi
 * @param $targetWidth - istenen çıktı genişliği
 * @param $targetHeight - istediğiniz çıktı yüksekliği veya boş
 * @return mixed|null
 */
function yeniden_boyutlandır($src, $dest, $targetWidth, $targetHeight = null) {
    $type = exif_imagetype($src);
    if (!$type || !IMAGE_HANDLERS[$type]) {
        return null;
    }
    $image = call_user_func(IMAGE_HANDLERS[$type]['load'], $src);
    if (!$image) {
        return null;
    }
    $width = imagesx($image);
    $height = imagesy($image);
    if ($targetHeight == null) {
        $ratio = $width / $height;
        if ($width > $height) {
            $targetHeight = floor($targetWidth / $ratio);
        }
        else {
            $targetHeight = $targetWidth;
            $targetWidth = floor($targetWidth * $ratio);
        }
    }
    $thumbnail = imagecreatetruecolor($targetWidth, $targetHeight);
    if ($type == IMAGETYPE_GIF || $type == IMAGETYPE_PNG) {
        imagecolortransparent(
            $thumbnail,
            imagecolorallocate($thumbnail, 0, 0, 0)
        );
        if ($type == IMAGETYPE_PNG) {
            imagealphablending($thumbnail, false);
            imagesavealpha($thumbnail, true);
        }
    }
    imagecopyresampled(
        $thumbnail,
        $image,
        0, 0, 0, 0,
        $targetWidth, $targetHeight,
        $width, $height
    );
    return call_user_func(
        IMAGE_HANDLERS[$type]['save'],
        $thumbnail,
        $dest,
        IMAGE_HANDLERS[$type]['quality']
    );
}
Kullanılışı;
move_uploaded_file fonksiyonundan sonra yazın
resyukle($resim_klasoru.$dosya_adi, $resim_klasoru.$dosya_adi, 500)
Veya yazılanları yapabilirseniz bu konuma da göz atabilirsiniz.
 
  
 
                    