lsolesen\pel\PelIfd::safeSetThumbnail PHP Method

safeSetThumbnail() private method

It is safe to call this method repeatedly with either the offset or the length set to zero, since it requires both of these arguments to be positive before the thumbnail is extracted. When both parameters are set it will check the length against the available data and adjust as necessary. Only then is the thumbnail data loaded.
private safeSetThumbnail ( lsolesen\pel\PelDataWindow $d, integer $offset, integer $length )
$d lsolesen\pel\PelDataWindow the data from which the thumbnail will be extracted.
$offset integer the offset into the data.
$length integer the length of the thumbnail.
    private function safeSetThumbnail(PelDataWindow $d, $offset, $length)
    {
        /*
         * Load the thumbnail if both the offset and the length is
         * available.
         */
        if ($offset > 0 && $length > 0) {
            /*
             * Some images have a broken length, so we try to carefully
             * check the length before we store the thumbnail.
             */
            if ($offset + $length > $d->getSize()) {
                Pel::maybeThrow(new PelIfdException('Thumbnail length %d bytes ' . 'adjusted to %d bytes.', $length, $d->getSize() - $offset));
                $length = $d->getSize() - $offset;
            }
            /* Now set the thumbnail normally. */
            $this->setThumbnail($d->getClone($offset, $length));
        }
    }