How to Create Flexify Image using PHP

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.

Read Also:  PHP Laravel Store Array in Session Examples

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


<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"/>


$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.";
} else if($fileSize > 5242880) { 
    echo "ERROR: Your file was larger than 5 Megabytes in size.";
} else if (!preg_match("/.(gif|jpg|png)$/i", $upload_fl_name) ) {
     echo "sorry ERROR: Your image was not .gif, .jpg, or .png.";
} else if ($result_errors == 1) { 
    echo "sorry, ERROR: An error occured while processing the file. Try again.";

$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
unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder

$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";


Read Also:  Top 40 Laravel Interview Questions

Function for resizing jpg, gif, or png image files

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:  Laravel Fullcalendar Integration Tutorial Example From Scratch


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 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.

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *