ColorThief\VBox::volume PHP Method

volume() public method

public volume ( $force = false )
    public function volume($force = false)
    {
        if (!$this->volume || $force) {
            $this->volume = ($this->r2 - $this->r1 + 1) * ($this->g2 - $this->g1 + 1) * ($this->b2 - $this->b1 + 1);
        }
        return $this->volume;
    }

Usage Example

Example #1
0
 /**
  * @covers ColorThief\VBox::volume
  */
 public function testVolume()
 {
     $this->vbox->r1 = 0;
     $this->vbox->r2 = 0;
     $this->vbox->g1 = 0;
     $this->vbox->g2 = 0;
     $this->vbox->b1 = 0;
     $this->vbox->b2 = 0;
     $this->assertSame(1, $this->vbox->volume());
     $this->vbox->r2 = 255;
     $this->vbox->g2 = 255;
     $this->vbox->b2 = 255;
     // Previous result should be cached.
     $this->assertSame(1, $this->vbox->volume());
     // Forcing refresh should now give the right result
     $this->assertSame(16777216, $this->vbox->volume(true));
 }