PHP Classes

File: ajaxcompress.php

Recommend this page to a friend!
  Classes of Adeleye Ayodeji   PHP Image Compressor on Upload   ajaxcompress.php   Download  
File: ajaxcompress.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: PHP Image Compressor on Upload
Compress uploaded image file reducing its quality
Author: By
Last change:
Date: 0 years ago
Size: 1,412 bytes
 

Contents

Class file image Download
<?php
   
//Compressing image on the go with PHP
    //Compress on the go
       
function compressImageonthego($source, $quality) {
           
//Getting image info
           
$info = getimagesize($source);
           
//Getting image extension
           
$fullparth = $source;
           
$imagepart = explode("https://result.maxfemcollege.com.ng/images/",$fullparth);
           
//print_r ($imagepart);

           
$rewriteimg = explode(".",$imagepart[1]);
           
//print_r($rewriteimg);
           
            //Writting new file name
           
$newname = "temp".rand(10,100);
           
//If image is jpeg by info
           
if ($info['mime'] == 'image/jpeg')
               
$image = imagecreatefromjpeg($source);
           
//If image is gif by info
           
elseif ($info['mime'] == 'image/gif')
               
$image = imagecreatefromgif($source);
           
//If image is png by info
           
elseif ($info['mime'] == 'image/png')
               
$image = imagecreatefrompng($source);
           
//Upload in a new location or override current
          
if(imagejpeg($image, "images/".$rewriteimg[0].".".$rewriteimg[1] ,$quality)){
               
//Error new url
              
echo "images/".$rewriteimg[0].".".$rewriteimg[1];
               }
        }
        if (isset(
$_GET["imageurl"])) {
           
$imageurl = $_GET["imageurl"];
        }
       
compressImageonthego($imageurl, 20);
?>