public function offsetSet($offset, $value)
    {
        // no offset means append
        if ($offset === null) {
            $offset = $this->bands;
        }

        if (!is_int($offset)) {
            throw new \BadMethodCallException('Image::offsetSet: offset is not integer or null');
        }

        // number of bands to the left and right of $value
        $n_left = min($this->bands, max(0, $offset));
        $n_right = min($this->bands, max(0, $this->bands - 1 - $offset));
        $offset = $this->bands - $n_right;

        // if we are setting a constant as the first element, we must expand it
        // to an image, since bandjoin must have an image as the first argument
        if ($n_left === 0 && !($value instanceof Image)) {
            $value = self::imageize($this, $value);
        }

        $components = [];
        if ($n_left > 0) {
            $components[] = $this->extract_band(0, ['n' => $n_left]);
        }
        $components[] = $value;
        if ($n_right > 0) {
            $components[] = $this->extract_band($offset, ['n' => $n_right]);
        }

        $head = array_shift($components);
        $this->image = $head->bandjoin($components)->image;
    }
public function offsetSet($offset, $value)
    {
        // no offset means append
        if ($offset === null) {
            $offset = $this->bands;
        }

        if (!is_int($offset)) {
            throw new \BadMethodCallException('Image::offsetSet: offset is not integer or null');
        }

        // number of bands to the left and right of $value
        $n_left = min($this->bands, max(0, $offset));
        $n_right = min($this->bands, max(0, $this->bands - 1 - $offset));
        $offset = $this->bands - $n_right;

        // if we are setting a constant as the first element, we must expand it
        // to an image, since bandjoin must have an image as the first argument
        if ($n_left === 0 && !($value instanceof Image)) {
            $value = self::imageize($this, $value);
        }

        $components = [];
        if ($n_left > 0) {
            $components[] = $this->extract_band(0, ['n' => $n_left]);
        }
        $components[] = $value;
        if ($n_right > 0) {
            $components[] = $this->extract_band($offset, ['n' => $n_right]);
        }

        $head = array_shift($components);
        $this->image = $head->bandjoin($components)->image;
    }
public function offsetSet ( $ offset , $ value ) { // no offset means append if ( $ offset === null ) { $ offset = $ this -> bands ; } if ( ! is_int ( $ offset ) ) { throw new \ BadMethodCallException ( 'Image::offsetSet: offset is not integer or null' ) ; } // number of bands to the left and right of $value $ n_left = min ( $ this -> bands , max ( 0 , $ offset ) ) ; $ n_right = min ( $ this -> bands , max ( 0 , $ this -> bands - 1 - $ offset ) ) ; $ offset = $ this -> bands - $ n_right ; // if we are setting a constant as the first element, we must expand it // to an image, since bandjoin must have an image as the first argument if ( $ n_left === 0 && ! ( $ value instanceof Image ) ) { $ value = self :: imageize ( $ this , $ value ) ; } $ components = [ ] ; if ( $ n_left > 0 ) { $ components [ ] = $ this -> extract_band ( 0 , [ 'n' => $ n_left ] ) ; } $ components [ ] = $ value ; if ( $ n_right > 0 ) { $ components [ ] = $ this -> extract_band ( $ offset , [ 'n' => $ n_right ] ) ; } $ head = array_shift ( $ components ) ; $ this -> image = $ head -> bandjoin ( $ components ) -> image ; }
Set a band.

Use `$image[1] = $other_image;' to remove band 1 from this image,
replacing it with all the bands in `$other_image`.

Use `$image[] = $other_image;' to append all the bands in `$other_image`
to `$image`.

Use `$image[-1] = $other_image;` to prepend all the bands in
`$other_image` to `$image`.

You can use constants or arrays in place of `$other_image`. Use `$image[]
= 255;` to append a constant 255 band, for example, or `$image[1]
= [1, 2];` to replace band 1 with two constant bands.

@param int   $offset The index to set.
@param Image $value  The band to insert

@throws \BadMethodCallException if the offset is not integer or null
@throws Exception

@return void
Set a band .