eihror / compress-image

Compress your image without losing quality
MIT License
33 stars 19 forks source link

Not working on the Server #10

Open shakzee opened 5 years ago

shakzee commented 5 years ago

Thanks for this library, its working fine in my local machine but when I upload the code on the server it was not compressing the image (not giving any error).

Here is my code:

$compressFile = realpath(APPPATH . '../assets/images/machineImages/'.$myImgcom->mim_name);
$compressImageName = 'myImageName';
$comporessQuality = 70;
$comporessDestination = realpath(APPPATH . '../assets/images/machineImages');
$image_compress = new Eihror\Compress\Compress($compressFile, $compressImageName, $comporessQuality, 9, $comporessDestination);
                            $isComprs = $image_compress->compress_image();
joaquinpco commented 5 years ago

Used in a Linux Laravel web server and it works. Check your namespaces and includes. :)

shakzee commented 5 years ago

I am using this library in CodeIgniter. my Server is AWS ubuntu, i have also checked the namespaces

<?php
namespace Eihror\Compress;

class Compress {

    // @var file_url
    protected $file_url;

    // @var new_name_image
    protected $new_name_image;

    // @var quality
    protected $quality;

    // @var quality
    protected $pngQuality;

    // @var destination
    protected $destination;

    // @var image_size
    protected $image_size;

    // @var image_data
    protected $image_data;

    // @var image_mime
    protected $image_mime;

    // @var array_img_types
    protected $array_img_types;
joaquinpco commented 5 years ago

How have you settled in your project eihror/compress-image/ via composer require or downloading file? If you choose second way, functions used it inside compressor as imagejpeg https://www.php.net/manual/es/function.imagejpeg.php are in php api. Hope that it helps :)

shakzee commented 5 years ago

I have downloaded the files via composer

AjithLalps commented 5 years ago

Is this issue fixed??

shakzee commented 5 years ago

not still exist, I have tested on the AWS and also on Cpanel but it's not working. it's working on localhost

On Sun, Jun 23, 2019 at 9:09 PM Ajith Lal notifications@github.com wrote:

Is thia issue fixed??

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eihror/compress-image/issues/10?email_source=notifications&email_token=AGSJTHULCYM6JWETHH6XT6LP36N2PA5CNFSM4HRAHWWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYLBYUA#issuecomment-504765520, or mute the thread https://github.com/notifications/unsubscribe-auth/AGSJTHRAOFUAIQVI4ODYOHLP36N2PANCNFSM4HRAHWWA .

AjithLalps commented 5 years ago

Did you checked the error log?

shakzee commented 5 years ago

Yes, I have checked also with var_dump(); method :( It's awesome library but not working on Cpanel and AWS

On Sun, Jun 23, 2019 at 9:10 PM Ajith Lal notifications@github.com wrote:

Did you checked the error log?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/eihror/compress-image/issues/10?email_source=notifications&email_token=AGSJTHX2ORRXFJTKEWEGDW3P4BCJ3A5CNFSM4HRAHWWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYLWL5Q#issuecomment-504849910, or mute the thread https://github.com/notifications/unsubscribe-auth/AGSJTHRWVH2JKDLHMIA7QP3P4BCJ3ANCNFSM4HRAHWWA .

AjithLalps commented 5 years ago

could you check the error log on cpanel?

shakzee commented 5 years ago

I have checked the error log it's not giving/generating any error. Here is my code

public function compressAction()
    {
        if (isAdmin()) {
           // $reduction =  $this->input->post('reduction',TRUE);//reduction how much % a image comporessed
            $ImagesId = $this->input->post('imageValues',TRUE);
            if ( empty($ImagesId))//empty($reduction) ||
            {
                customFlash('alert-warning','Please check required field and try again.','admin/compress-images');
            }
            else{
                $myImges = $this->modAdmin->checkAllImages($ImagesId); //$ImagesId  this is an array coming from view

                //var_dump($myImges);
                if ($myImges->num_rows() > 0) {
                    $this->load->library('Compress');
                    $compData = array();
                    $imagePath = realpath(APPPATH . '../assets/images/machineImages');
                    foreach ($myImges->result() as $myImgcom){
                        $myImg = realpath(APPPATH . '../assets/images/machineImages/');
                        ///echo $myImg.$myImgcom->mim_name;
                        $ImageId  = $myImgcom->mim_id;
                        $oldImageSize = formatBytes(filesize($myImg.'/'.$myImgcom->mim_name));
                        $fileSizeSkz = imageSizeBytes(filesize($myImg.'/'.$myImgcom->mim_name));

                        $compDate  = date('Y-m-d H:i:s');
                        if (file_exists($imagePath.'/'.$myImgcom->mim_name)){
                            $compressFile = base_url('assets/images/machineImages/'.$myImgcom->mim_name);
                            //$compressFile = realpath(APPPATH . '../assets/images/machineImages/'.$myImgcom->mim_name);
                            $compressImageName = $myImgcom->mim_name;
                            //$comporessQuality = $reduction; // reduction value in % i.e 10% or 20% coming from html form
                            $comporessDestination = base_url().'assets/images/machineImages';
                            //$comporessDestination = realpath(APPPATH . '../assets/images/machineImages');

                            //echo img($compressFile);

                            $compress0 = new Compress();
                            $compress0->file_url = $compressFile;
                            $compress0->new_name_image = $compressImageName;
                            if ($fileSizeSkz >=  1 && $fileSizeSkz <=75) {
                                $comporessQuality = 85;
                            }
                            /*else if ($fileSizeSkz >=  51 && $fileSizeSkz <=75) {
                                $comporessQuality = 85  ;
                            }*/
                            else if ($fileSizeSkz >= 76 && $fileSizeSkz <=100) {
                                $comporessQuality = 80;
                            }
                            else if ($fileSizeSkz >=  101 && $fileSizeSkz <=150) {
                                $comporessQuality = 70;
                            }
                            else if ($fileSizeSkz >= 151 && $fileSizeSkz <=200) {
                                $comporessQuality = 65;
                            }
                            else if ($fileSizeSkz >=  201 && $fileSizeSkz <=350) {
                                $comporessQuality = 60;
                            }
                            else if ($fileSizeSkz >=  351 && $fileSizeSkz <=650) {
                                $comporessQuality = 55;
                            }
                            else if ($fileSizeSkz >=  651 && $fileSizeSkz <=800) {
                                $comporessQuality = 50;
                            }
                            else if ($fileSizeSkz >=  801 && $fileSizeSkz <=999) {
                                $comporessQuality = 45;
                            }
                            else if ($fileSizeSkz >=  1000) {
                                $comporessQuality = 40;
                            }
                            $compress0->quality = $comporessQuality;

                            $compress0->pngQuality  = 9;
                            $compress0->destination = $comporessDestination;
                            $result0 = $compress0->compress_image();
                            $newImageSize = formatBytes(filesize($myImg.'/'.$myImgcom->mim_name));
                            $isComplressed =  true;
                            $isComment =  '';
                            $compData[] = array(
                                'image_id'=>$ImageId,
                                'imcm_old_image'=>$oldImageSize,
                                'imcm_new_image'=>$newImageSize,
                                'imcm_is_comporessed'=>$isComplressed,
                                'imcm_comment'=>$isComment,
                                'imcm_date'=>$compDate,
                            );

                        }
                        else{
                            $compData[] = array(
                                'image_id'=>$ImageId,
                                'imcm_old_image'=>'',
                                'imcm_new_image'=>'',
                                'imcm_is_comporessed'=>false,
                                'imcm_comment'=>'Images is not exist on server/folder',
                                'imcm_date'=>$compDate,
                            );
                        }

                        /*$compData[] = array(
                            'old_size'=>formatBytes(filesize($myImg)),
                            'image_id'=>$myImgcom->mim_id
                        );*/

                        //echo '<br>';
                    }//foreach loop here

                    $myImage = $this->modAdmin->addComporessedImgaes($compData);
                    if ($myImage) {
                        customFlash('alert-success','Your images have been successfully compressed.','admin/compress-images');
                    }
                    else{
                        customFlash('alert-warning','You can\'t compress the images right now please try again.','admin/compress-images');
                    }
                    //var_dump($compData);
                }
                else{
                    echo 'Images not found.';
                }
                //echo $myImges->num_rows();
                //var_dump($this->input->post('imageValues',true));
            }
        }
        else{
            customFlash('alert-danger','Please login first to access the admin panel','admin/login');
        }

        //var_dump($this->input->post('imageValues',true));
    }

Result imageProblem

Error log [Mon Jun 24 11:23:04.897351 2019] [autoindex:error] [pid 975126:tid 139700177692416] [client 202.47.32.196:0] AH01276: Cannot serve directory /home/Domain/public_html/: No matching DirectoryIndex (index.html.var,index.htm,index.html,index.shtml,index.xhtml,index.wml,index.perl,index.pl,index.plx,index.ppl,index.cgi,index.jsp,index.js,index.jp,index.php4,index.php3,index.php,index.phtml,default.htm,default.html,home.htm,index.php5,Default.html,Default.htm,home.html) found, and server-generated directory index forbidden by Options directive

AjithLalps commented 5 years ago

@shakzee please rewrite the code and check


<?php

public function compressAction()
{
if (isAdmin()) {
// $reduction =  $this->input->post('reduction',TRUE);//reduction how much % a image comporessed
$ImagesId = $this->input->post('imageValues',TRUE);
if ( empty($ImagesId))//empty($reduction) ||
{
customFlash('alert-warning','Please check required field and try again.','admin/compress-images');
}
else{
$myImges = $this->modAdmin->checkAllImages($ImagesId); //$ImagesId  this is an array coming from view

//var_dump($myImges);
if ($myImges->num_rows() > 0) {
$this->load->library('Compress');
$compData = array();
$imagePath = realpath(APPPATH . '../assets/images/machineImages');
foreach ($myImges->result() as $myImgcom){
$myImg = realpath(APPPATH . '../assets/images/machineImages/');
///echo $myImg.$myImgcom->mim_name;
$ImageId  = $myImgcom->mim_id;
$oldImageSize = formatBytes(filesize($myImg.'/'.$myImgcom->mim_name));
$fileSizeSkz = imageSizeBytes(filesize($myImg.'/'.$myImgcom->mim_name));

$compDate  = date('Y-m-d H:i:s');
if (file_exists($imagePath.'/'.$myImgcom->mim_name)){
$compressFile = base_url('assets/images/machineImages/'.$myImgcom->mim_name);
//$compressFile = realpath(APPPATH . '../assets/images/machineImages/'.$myImgcom->mim_name);
$compressImageName = $myImgcom->mim_name;
//$comporessQuality = $reduction; // reduction value in % i.e 10% or 20% coming from html form
$comporessDestination = base_url().'assets/images/machineImages';
//$comporessDestination = realpath(APPPATH . '../assets/images/machineImages');

//echo img($compressFile);
$comporessQuality='';
if ($fileSizeSkz >=  1 && $fileSizeSkz <=75) {
$comporessQuality = 85;
}
/*else if ($fileSizeSkz >=  51 && $fileSizeSkz <=75) {
$comporessQuality = 85  ;
}*/
else if ($fileSizeSkz >= 76 && $fileSizeSkz <=100) {
$comporessQuality = 80;
}
else if ($fileSizeSkz >=  101 && $fileSizeSkz <=150) {
$comporessQuality = 70;
}
else if ($fileSizeSkz >= 151 && $fileSizeSkz <=200) {
$comporessQuality = 65;
}
else if ($fileSizeSkz >=  201 && $fileSizeSkz <=350) {
$comporessQuality = 60;
}
else if ($fileSizeSkz >=  351 && $fileSizeSkz <=650) {
$comporessQuality = 55;
}
else if ($fileSizeSkz >=  651 && $fileSizeSkz <=800) {
$comporessQuality = 50;
}
else if ($fileSizeSkz >=  801 && $fileSizeSkz <=999) {
$comporessQuality = 45;
}
else if ($fileSizeSkz >=  1000) {
$comporessQuality = 40;
}
$pngQuality  = 9;
$compress0 = new Compress($compressFile,$compressImageName,$comporessQuality,$pngQuality,$comporessDestination);
$result0 = $compress0->compress_image();
$newImageSize = formatBytes(filesize($myImg.'/'.$myImgcom->mim_name));
$isComplressed =  true;
$isComment =  '';
$compData[] = array(
'image_id'=>$ImageId,
'imcm_old_image'=>$oldImageSize,
'imcm_new_image'=>$newImageSize,
'imcm_is_comporessed'=>$isComplressed,
'imcm_comment'=>$isComment,
'imcm_date'=>$compDate,
);

}
else{
$compData[] = array(
'image_id'=>$ImageId,
'imcm_old_image'=>'',
'imcm_new_image'=>'',
'imcm_is_comporessed'=>false,
'imcm_comment'=>'Images is not exist on server/folder',
'imcm_date'=>$compDate,
);
}

/*$compData[] = array(
'old_size'=>formatBytes(filesize($myImg)),
'image_id'=>$myImgcom->mim_id
);*/

//echo '<br>';
}//foreach loop here

$myImage = $this->modAdmin->addComporessedImgaes($compData);
if ($myImage) {
customFlash('alert-success','Your images have been successfully compressed.','admin/compress-images');
}
else{
customFlash('alert-warning','You can\'t compress the images right now please try again.','admin/compress-images');
}
//var_dump($compData);
}
else{
echo 'Images not found.';
}
//echo $myImges->num_rows();
//var_dump($this->input->post('imageValues',true));
}
}
else{
customFlash('alert-danger','Please login first to access the admin panel','admin/login');
}

//var_dump($this->input->post('imageValues',true));
}
shakzee commented 5 years ago

:( not solved