How to Create Flexify Image using PHP

Today, We want to share with you How to Create Flexify Image using PHP.In this post we will show you PHP Flexify Product Feed Fill with Fit, hear for PHP image manipulation Fits and Fill we will give you demo and example for implement.In this post, we will learn about PHP Automatic Flexify image resizing with an example.

How to Create Flexify Image using PHP

There are the Following The simple About How to Create Flexify Image using PHP Full Information With Example and source code.

As I will cover this Post with live Working example to develop flexify Product image, so the PHP Flexify – Facebook Product Feed structures for this example is following below.

Simple PHP Into Image Resize Function Tutorial jpg gif png Change Size

my_file.php

<form enctype="multipart/form-data" method="post" action="image_upload_script.php">
Choose your file here:
<input name="live_uploaded" type="file"/><br /><br />
<input type="submit" value="Upload It"/>
</form>

image_upload_script.php

<?php
$upload_fl_name = $_FILES["live_uploaded"]["name"];
$fileTmpLoc = $_FILES["live_uploaded"]["tmp_name"]; 
$fileType = $_FILES["live_uploaded"]["type"]; 
$fileSize = $_FILES["live_uploaded"]["size"]; 
$result_errors = $_FILES["live_uploaded"]["error"]; 
$kaboom = explode(".", $upload_fl_name); 
$fileExt = end($kaboom);
if (!$fileTmpLoc) { 
    echo "ERROR: Please browse for a file before clicking the upload button.";
    exit();
} else if($fileSize > 5242880) { 
    echo "ERROR: Your file was larger than 5 Megabytes in size.";
    unlink($fileTmpLoc); 
    exit();
} else if (!preg_match("/.(gif|jpg|png)$/i", $upload_fl_name) ) {
   
     echo "sorry ERROR: Your image was not .gif, .jpg, or .png.";
     unlink($fileTmpLoc);
     exit();
} else if ($result_errors == 1) { 
    echo "sorry, ERROR: An error occured while processing the file. Try again.";
    exit();
}

$moveResult = move_uploaded_file($fileTmpLoc, "uploads/$upload_fl_name");

if ($moveResult != true) {
    echo "Sorry ERROR: File not uploaded. Try again.";
    unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
    exit();
}
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder

include_once("ak_php_files_lib_1.0.php");
$final_t_file = "uploads/$upload_fl_name";
$resized_file = "uploads/resized_$upload_fl_name";
$wmax = 200;
$hmax = 150;
pakainfo_files_resize($final_t_file, $resized_file, $wmax, $hmax, $fileExt);

echo "The file named <strong>$upload_fl_name</strong> uploaded successfuly.<br /><br />";
echo "It is <strong>$fileSize</strong> bytes in size.<br /><br />";
echo "It is an <strong>$fileType</strong> type of file.<br /><br />";
echo "The file extension is <strong>$fileExt</strong><br /><br />";
echo "The Error Message output for this upload is: $result_errors";
?>

ak_php_files_lib_1.0.php

Read Also:  php string length - The Best PHP 3 Examples

Function for resizing jpg, gif, or png image files

<?php
function pakainfo_files_resize($final_t, $newcopy, $w, $h, $ext) {
    list($width_orignal, $height_orignal) = getimagesize($final_t);
    $prop_ratio_files = $width_orignal / $height_orignal;
    if (($w / $h) > $prop_ratio_files) {
           $w = $h * $prop_ratio_files;
    } else {
           $h = $w / $prop_ratio_files;
    }
    $files = "";
    $ext = strtolower($ext);
    if ($ext == "gif"){ 
      $files = imagecreatefromgif($final_t);
    } else if($ext =="png"){ 
      $files = imagecreatefrompng($final_t);
    } else { 
      $files = imagecreatefromjpeg($final_t);
    }
    $tci = imagecreatetruecolor($w, $h);
  
    imagecopyresampled($tci, $files, 0, 0, 0, 0, $w, $h, $width_orignal, $height_orignal);
    imagejpeg($tci, $newcopy, 80);
}
?>

Web Programming Tutorials Example with Demo

Read :

Read Also:  PHP Google Two Factor Authentication With CodeIgniter 3

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about How to Create Flexify Image using PHP.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.