Case Study – Use ImageRecycle to Save Over 2GB Storage on VPS


As you might know, the storage (HDD or SSD) on VPS server are expensive. That is why the VPS may seem overpricing the HDD/SSD storage e.g. 50GB costs like 50 pounds per year.

My image-uploading website keep original images together with other thumbnails. The original images can take up to 5MB per file, which is costly. Without resizing the original images (preserve high quality of images), the ImageRecycle seems a good choice.

Based on the PHP script provided in this post, we just need to check each image and optimise them.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  $query = "SELECT `url`,`id`,`size` FROM `pic` where `flag`&128=0";
  
  $result = $conn->query($query);
  
  $total_save = 0;
  $total = 0; 
  if ($result) {
    foreach ($result as $row) {
      $url = $row['url'];
      if (file_exists($url)) {
        $total ++;
        echo "Index = $total\n";
        echo $url . "\n";    
        $sz = filesize($url);
        echo "Original Size = $sz\n";
        ImageRecycle($url, $key, $secret);
        $sz1 = filesize($url);
        echo "Optimised Size = $sz1\n";
        $total_save += ($sz1 - $sz);
        echo "Total Save = $total_save\n";
        $fz = $row['size'];
        if ($sz1 != $fz) {    
          $id = $row['id'];
          $conn->query(
            "
                update `pic` set `flag`=`flag`|128 where `id`='$id'
            "
          );   
        }
      }
    }
  }    
  $query = "SELECT `url`,`id`,`size` FROM `pic` where `flag`&128=0";
  
  $result = $conn->query($query);
  
  $total_save = 0;
  $total = 0; 
  if ($result) {
    foreach ($result as $row) {
      $url = $row['url'];
      if (file_exists($url)) {
        $total ++;
        echo "Index = $total\n";
        echo $url . "\n";    
        $sz = filesize($url);
        echo "Original Size = $sz\n";
        ImageRecycle($url, $key, $secret);
        $sz1 = filesize($url);
        echo "Optimised Size = $sz1\n";
        $total_save += ($sz1 - $sz);
        echo "Total Save = $total_save\n";
        $fz = $row['size'];
        if ($sz1 != $fz) {    
          $id = $row['id'];
          $conn->query(
            "
                update `pic` set `flag`=`flag`|128 where `id`='$id'
            "
          );   
        }
      }
    }
  }    

Here, we use the flag bit 128 to represent if the images are optimised by ImageRecycle. The savings are tremendous!

Over 6000 images are optimised.

Join ImageRecycle and use the coupon IR-PARTNER-20 to get 20% off on first invoice, exclusive for my readers!

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
412 words
Last Post: Comparing ImageRecycle and Imagfy - Which is Better?
Next Post: Processing Coding Exercise - Fibonacci Flowers

The Permanent URL is: Case Study – Use ImageRecycle to Save Over 2GB Storage on VPS (AMP Version)

Leave a Reply