*

StefanGr

  • ***
  • 51 posts
WebP Images generator - delete jpegs.
« on: May 19, 2022, 09:16:42 AM »
Hello, since i can't find the info, i'll post here.

Is there a possibility to ad an option to delete the jpegs / pngs after the conversion is made to Webp format ?
Is there a way to automatically delete the jpegs / pngs after they are converted to webp ? Since we got several thousand ads ,the image size  do stack up, eating away all the available hdd space...
;) nothing here, move on.

*

MB Themes

Re: WebP Images generator - delete jpegs.
« Reply #1 on: May 19, 2022, 09:34:36 AM »
@StefanGr
Not sure if this is best way to do it, but in theory possible, would need plugin update.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

StefanGr

  • ***
  • 51 posts
Re: WebP Images generator - delete jpegs.
« Reply #2 on: May 19, 2022, 09:38:45 AM »
maybe it should be taken in consideration for a next update.
Deleting them from ftp is a tedious job. Whats the point on having optimised images if you can't delete the standard one and free up space.
;) nothing here, move on.

*

MB Themes

Re: WebP Images generator - delete jpegs.
« Reply #3 on: May 19, 2022, 09:49:32 AM »
Yes will put it into list
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 475 posts
Re: WebP Images generator - delete jpegs.
« Reply #4 on: July 05, 2022, 04:05:05 PM »
@StefanGr

You can delete them with the use of cronjobs. I do this every night at 3am.
You need to set up multiple jobs for every folder...

i.e:   
rm -f /home/your-username/domains/yourdomain.be/public_html/oc-content/uploads/0/*.jpg
rm -f /home/your-username/domains/yourdomain.be/public_html/oc-content/uploads/1/*.jpg

rm -f /home/your-username/domains/yourdomain.be/public_html/oc-content/uploads/0/*.png
rm -f /home/your-username/domains/yourdomain.be/public_html/oc-content/uploads/1/*.png
etc.....
« Last Edit: July 05, 2022, 04:48:30 PM by mwindey »

*

MB Themes

Re: WebP Images generator - delete jpegs.
« Reply #5 on: July 06, 2022, 11:02:33 AM »
@mwindey
Nice, thanks ;)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 475 posts
Re: WebP Images generator - delete jpegs.
« Reply #6 on: August 19, 2022, 11:14:37 AM »
I am struggling with some code in a php file that i want to execute with cron every night after deleting files to update the t_item_resource table.
Deleting the images jpg etc works perfectly with the use of cron mentioned above but the item_resource table needs to be updated as well...
I am trying with a file called photocron.php and upload in public_html folder but it throws error 500.... Any suggestions please?
Code:
Code: [Select]
require once 'config.php';
require once 'oc-load.php';
mysql_query(
UPDATE oc_t_item_resource SET s_extension = 'webp' WHERE s_extension = 'jpg' OR s_extension = 'gif' OR s_extension= 'jpeg');
« Last Edit: August 20, 2022, 02:30:06 PM by mwindey »

*

mwindey

  • *****
  • 475 posts
Re: WebP Images generator - delete jpegs.
« Reply #7 on: August 21, 2022, 03:51:46 PM »
I am struggling with some code in a php file that i want to execute with cron every night after deleting files to update the t_item_resource table.
Deleting the images jpg etc works perfectly with the use of cron mentioned above but the item_resource table needs to be updated as well...
I am trying with a file called photocron.php and upload in public_html folder but it throws error 500.... Any suggestions please?
Code:
Code: [Select]
require once 'config.php';
require once 'oc-load.php';
mysql_query(
UPDATE oc_t_item_resource SET s_extension = 'webp' WHERE s_extension = 'jpg' OR s_extension = 'gif' OR s_extension= 'jpeg');

SOLVED and run cron at 3am:
Extra file connection.php
Code: [Select]
<?php
   $servername
='localhost';
   
$username='';
   
$password='';
   
$dbname "";
   
$connection=mysqli_connect($servername,$username,$password,"$dbname");
   if(!
$connection){
      die(
'Could not Connect My Sql:' .mysql_error());
   }
?>

New file cronpicture.php
Code: [Select]
<?php

include_once 'connection.php';
// Attempt update query execution
$sql "UPDATE oc_t_item_resource SET s_extension='webp' WHERE s_extension='jpg' OR s_extension='gif' OR s_extension='jpeg'";

// Close connection
mysqli_close($connection);
?>

« Last Edit: August 21, 2022, 03:53:56 PM by mwindey »

*

MB Themes

Re: WebP Images generator - delete jpegs.
« Reply #8 on: August 21, 2022, 04:47:57 PM »
Use DAO instead  ;)
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

mwindey

  • *****
  • 475 posts
Re: WebP Images generator - delete jpegs.
« Reply #9 on: August 21, 2022, 06:13:46 PM »
@MB Themes,

Much more safe but summertime makes me lazy :-) Maybe you are more active than me at the moment and spread some love sharing the solution in DAO :-)

*

bemtele

  • ***
  • 97 posts
Re: WebP Images generator - delete jpegs.
« Reply #10 on: August 22, 2022, 01:04:23 AM »
I am struggling with some code in a php file that i want to execute with cron every night after deleting files to update the t_item_resource table.
Deleting the images jpg etc works perfectly with the use of cron mentioned above but the item_resource table needs to be updated as well...
I am trying with a file called photocron.php and upload in public_html folder but it throws error 500.... Any suggestions please?
Code:
Code: [Select]
require once 'config.php';
require once 'oc-load.php';
mysql_query(
UPDATE oc_t_item_resource SET s_extension = 'webp' WHERE s_extension = 'jpg' OR s_extension = 'gif' OR s_extension= 'jpeg');

SOLVED and run cron at 3am:
Extra file connection.php
Code: [Select]
<?php
   $servername
='localhost';
   
$username='';
   
$password='';
   
$dbname "";
   
$connection=mysqli_connect($servername,$username,$password,"$dbname");
   if(!
$connection){
      die(
'Could not Connect My Sql:' .mysql_error());
   }
?>

New file cronpicture.php
Code: [Select]
<?php

include_once 'connection.php';
// Attempt update query execution
$sql "UPDATE oc_t_item_resource SET s_extension='webp' WHERE s_extension='jpg' OR s_extension='gif' OR s_extension='jpeg'";

// Close connection
mysqli_close($connection);
?>




Please can you add the cronjob command too?

*

mwindey

  • *****
  • 475 posts
Re: WebP Images generator - delete jpegs.
« Reply #11 on: August 22, 2022, 11:19:00 AM »
@MB Themes

First attempt.... Do you think this will work?
Code: [Select]
<?php
  
class ModelUP extends DAO {
  private static 
$instance;

  public static function 
newInstance() {
    if( !
self::$instance instanceof self ) {
      
self::$instance = new self;
    }
    return 
self::$instance;
  }

  function 
__construct() { 
    
parent::__construct(); 
  }

  public function 
getTable_item_resource() {
    return 
DB_TABLE_PREFIX.'t_item_resource';
  }

 public function 
update_item_resource($s_extension) {
    
$aSet = array(
      
's_extension' => webp
    
);

    
$aWhere = array(
      
'jpg' => $jpg,
      
'jpeg' => $jpeg,
      
'png' => $png,
      
'gif' => $gif
    
);
    return 
$this->_update($this->getTable_item_resource(), $aSet$aWhere);
  }  
?>

« Last Edit: August 22, 2022, 12:38:11 PM by mwindey »

*

mwindey

  • *****
  • 475 posts
Re: WebP Images generator - delete jpegs.
« Reply #12 on: August 22, 2022, 11:29:09 AM »
@bemtele

For directadmin: This wipes all jpg files at 3am

*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/0/*.jpg
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/1/*.jpg
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/2/*.jpg
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/3/*.jpg

Same for png files

*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/0/*.png
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/1/*.png
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/2/*.png
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/3/*.png

Same for gif
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/0/*.gif
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/1/*.gif
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/2/*.gif
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/3/*.gif

Next runs cronpicture.php file 1 minute later

1   3   1-31   1-12   0-7   /usr/local/bin/php -q -f /home/u44173*****/domains/domain.com/public_html/cronpicture.php >/dev/null 2>&1

I am only clearing jpg and jpeg files gif and png is not so much used
« Last Edit: August 22, 2022, 11:35:23 AM by mwindey »

*

MB Themes

Re: WebP Images generator - delete jpegs.
« Reply #13 on: August 22, 2022, 09:44:18 PM »
Use ->update or ->dao->update instead of _update, nowadays not needed too much
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

bemtele

  • ***
  • 97 posts
Re: WebP Images generator - delete jpegs.
« Reply #14 on: August 23, 2022, 03:13:31 PM »
@bemtele

For directadmin: This wipes all jpg files at 3am

*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/0/*.jpg
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/1/*.jpg
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/2/*.jpg
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/3/*.jpg

Same for png files

*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/0/*.png
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/1/*.png
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/2/*.png
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/3/*.png

Same for gif
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/0/*.gif
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/1/*.gif
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/2/*.gif
*   3   1-31   1-12   0-7   rm -f /home/u44173*****/domains/domain.com/public_html/oc-content/uploads/3/*.gif

Next runs cronpicture.php file 1 minute later

1   3   1-31   1-12   0-7   /usr/local/bin/php -q -f /home/u44173*****/domains/domain.com/public_html/cronpicture.php >/dev/null 2>&1

I am only clearing jpg and jpeg files gif and png is not so much used

Thank you @mwindey. I am waiting for the DAO too  8)