Search
 
SCRIPT & CODE EXAMPLE
 

PHP

PHP Image Resize

<?php
if (isset($_POST["submit"])) {
    if (is_array($_FILES)) {
        $file = $_FILES['myImage']['tmp_name'];
        $source_properties = getimagesize($file);
        $image_type = $source_properties[2];
        if ($image_type == IMAGETYPE_JPEG) {
            $image_resource_id = imagecreatefromjpeg($file);
            $target_layer = fn_resize($image_resource_id, $source_properties[0], $source_properties[1]);
            imagejpeg($target_layer, $_FILES['myImage']['name'] . "_thump.jpg");
        } elseif ($image_type == IMAGETYPE_GIF) {
            $image_resource_id = imagecreatefromgif($file);
            $target_layer = fn_resize($image_resource_id, $source_properties[0], $source_properties[1]);
            imagegif($target_layer, $_FILES['myImage']['name'] . "_thump.gif");
        } elseif ($image_type == IMAGETYPE_PNG) {
            $image_resource_id = imagecreatefrompng($file);
            $target_layer = fn_resize($image_resource_id, $source_properties[0], $source_properties[1]);
            imagepng($target_layer, $_FILES['myImage']['name'] . "_thump.png");
        }
    }
}

function fn_resize($image_resource_id, $width, $height)
{
    $target_width = 200;
    $target_height = 200;
    $target_layer = imagecreatetruecolor($target_width, $target_height);
    imagecopyresampled($target_layer, $image_resource_id, 0, 0, 0, 0, $target_width, $target_height, $width, $height);
    return $target_layer;
}
?>
<form name="frmImageResize" action="" method="post"
	enctype="multipart/form-data">
	<input type="file" name="myImage" /> <input type="submit" name="submit" value="Submit" />
</form>
Comment

PREVIOUS NEXT
Code Example
Php :: get data of url php 
Php :: php close unclosed HTML Tags 
Php :: wp_login_form wrong password redirect 
Php :: php rand int 
Php :: how to add page link in laravel 
Php :: laravel vue 
Php :: laravel model fillable vs guarded 
Php :: laravel where not equal 
Php :: how to redirect to another page after login in laravel 
Php :: php function crop image 
Php :: laravel merge two query builder 
Php :: php ?? 
Php :: create child theme in wordpress 
Php :: laravel drop table migration 
Php :: adding data dynamically to empty array in php 
Php :: laravel model with migration 
Php :: php timezone change 
Php :: php current time 
Php :: laravel mail send 
Php :: add custom post type wordpress 
Php :: update image in database using php 
Php :: laravel latest from relationship 
Php :: clear cache symfony 
Php :: copy php array to another 
Php :: convertir datetime a string en php 
Php :: php foreach array pop 
Php :: Encrypt in PHP openssl and decrypt in javascript CryptoJS 
Php :: php indexof 
Php :: all resource routes laravel 8 
Php :: php check if string is integer 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =