Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
Webp Image (work in progress)
Controls ·  Search New posts · Mark unread

You are in: Forum / Forum / General / General Chat

2022-10-05 11:52:47
Currently changing all images to webp - webp images are a lot  smaller

This uses the gd extension and will save loads of space. As far as i know most browsers support webp.

I added check if gd added or use php copy
where ever copy is we just will add new function passing source and destination so edits are small

function copyImage($source, $destination, $redirect = URLROOT)
{
   if (extension_loaded('gd')) {
       // compress size max 100
       $compression_quality = 25;
       // set type
       $type = substr($destination, -3);
       $jpeg = substr($destination, -4);
       // set destination
       $new_destination = substr($destination, 0, -3) . 'webp';
               
       if ($type == 'png') {
           $image = imagecreatefrompng($source);
           imagepalettetotruecolor($image);
           imagealphablending($image, true);
           imagesavealpha($image, true);
       } elseif ($type == 'jpg') {
           $image = imagecreatefromjpeg($source);
       } elseif ($type == 'gif') {
           $image = imagecreatefromgif($source);
           imagepalettetotruecolor($image);
       } elseif ($jpeg == 'jpeg') {
           $image = imagecreatefromjpeg($source);
           $new_destination = substr($destination, 0, -4) . 'webp';
       } else {
           Redirect::autolink($redirect, sprintf(Lang::T("Strange Image Type")));
       }

       // convert image
       $result = imagewebp($image, $new_destination, $compression_quality);
       // check result
       if (false === $result) {
           Redirect::autolink($redirect, sprintf(Lang::T("No Image Result")));
       }
       // destroy temp
       imagedestroy($image);
       return $new_destination;
   } else {
       $copy = copy($source, $destination);
       if (!$copy) {
           Redirect::autolink($redirect, sprintf(Lang::T("IMAGE_UPLOAD_FAILED")));
       }
       return $destination;
   }
}




Example For TMDB posters under saveimage i used this - halving image sizes
        if (extension_loaded('gd')) {
           copyImage(UPLOADDIR . "/tmdb/film/$id_tmdb.jpg", UPLOADDIR . "/tmdb/film/$id_tmdb.jpg");
           unlink(UPLOADDIR . "/tmdb/film/$id_tmdb.jpg");
           unlink(CACHE . "/tmdb/film/$id_tmdb.cache");
           $image = "$id_tmdb.webp";
       }
Last edited by M-jay warn on 2022-10-06 08:40:52
2022-10-06 15:59:39
Thank you!
2022-10-06 17:32:08
happy to share just got a few more areas to do

on torrents-upload example
$ifilename = $next_id . $x . $allowed_types[$im['mime']];


below should look like
                    $image_name = copyImage($ifile, $uploaddir . $ifilename);
                   $inames[] = $image_name;


so minimum edits

made a convertor too for existing images seems to time out after around 20 images - bit of a pain converting all country flags lol lucky i moved to icons and removed most images - for old uploaded images i used something similar to the TMDB edit in post above to write to webp then unlink the old file to phase them out

convertor
        if (Input::exist()) {
$files = array_filter($_FILES['upload']['name']); //Use something similar before processing files.
// Count the number of uploaded files in array
$total_count = count($_FILES['upload']['name']);
// Loop through every file
for( $i=0 ; $i < $total_count ; $i++ ) {
  //The temp file path is obtained
   $source_file = $_FILES['upload']['tmp_name'][$i];
  //A file path needs to be present
  if ($source_file != ""){
     $newname = $_FILES['upload']['name'][$i];
     $destination_file = "assets/images/$newname"; //URLROOT."/$newname";
     //File is uploaded to temp dir
     echo 'temp file<pre>'.print_r($source_file, true).'</pre><br>';
     echo 'name<pre>'.print_r($newname, true).'</pre><br>';
     echo 'filepath<pre>'.print_r($destination_file, true).'</pre><br>';
     
     copyImage($source_file, $destination_file);
     
  }
}
}

?>

<form action="<?php echo URLROOT ?>/test/upload" method="post" enctype="multipart/form-data">
   Select Image Files to Upload:
   <input type="file" name="upload[]" multiple >
   <input type="submit" name="submit" value="UPLOAD">
</form>
2022-10-16 22:02:55
That converter is begging to read /uploads/images/* in a batch process.

I'll tinker with this and read the php.net docs

WebP appears to be supported since PHP 7.1
Last edited by STorrents2020 on 2022-10-16 22:03:51
2022-10-17 05:59:01
Finished switch to wepb my project size went from 3.2MB to now 1.3MB
that's with not using many images so the user upload folder  i imagine is going save loads  👍

The country gifs look like shit though lol but the quality of everything else is perfect I think it's because the flags were animated gifs
2022-10-17 18:00:18
Can you add those flags to a array white list? Thats a good point.
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 9
  • Members: 0
  • Guests online: 9
  • Comments: 3
  • Messages: 1,728