/** * Setter for the BO version number. * * @param int $versionNumber The version number. * * @since 1.0 */ private function setVersion($versionNumber) { $this->version_num->setValue($versionNumber); }
/** * Renders the actual binary image using GD library calls. * * @since 1.0 */ public function renderImage() { $config = ConfigProvider::getInstance(); // if scaled, we need to compute the target image size if ($this->scale->getBooleanValue() && isset($_COOKIE['screenSize'])) { $originalScreenResolution = explode('x', $config->get('sysCMSImagesWidgetScreenResolution')); $originalScreenX = $originalScreenResolution[0]; $originalScreenY = $originalScreenResolution[1]; $targetScreenResolution = explode('x', $_COOKIE['screenSize']); $targetScreenX = $targetScreenResolution[0]; $targetScreenY = $targetScreenResolution[1]; // calculate the new units we will scale by $xu = $targetScreenX / $originalScreenX; $yu = $targetScreenY / $originalScreenY; $this->width = new Integer(intval($this->width->getValue() * $xu)); $this->height = new Integer(intval($this->height->getValue() * $yu)); // need to update the cache filename as the dimensions have changed $this->setFilename(); } // check the image cache first before we proceed if ($this->checkCache()) { $this->loadCache(); } else { // now get the old image switch ($this->sourceType->getValue()) { case 'gif': $old_image = imagecreatefromgif($this->source); break; case 'jpg': $old_image = imagecreatefromjpeg($this->source); break; case 'png': $old_image = imagecreatefrompng($this->source); break; } if (!$old_image) { $im = imagecreatetruecolor($this->width->getValue(), $this->height->getValue()); $bgc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im, 0, 0, $this->width->getValue(), $this->height->getValue(), $bgc); imagestring($im, 1, 5, 5, "Error loading {$this->source}", $tc); if ($this->sourceType->getValue() == 'png' && $config->get('cms.images.perserve.png')) { imagepng($im); } else { imagejpeg($im); } imagedestroy($im); } else { // the dimensions of the source image $oldWidth = imagesx($old_image); $oldHeight = imagesy($old_image); // now create the new image $new_image = imagecreatetruecolor($this->width->getValue(), $this->height->getValue()); // set a transparent background for PNGs if ($this->sourceType->getValue() == 'png' && $config->get('cms.images.perserve.png')) { // Turn off transparency blending (temporarily) imagealphablending($new_image, false); // Create a new transparent color for image $color = imagecolorallocatealpha($new_image, 255, 0, 0, 0); // Completely fill the background of the new image with allocated color. imagefill($new_image, 0, 0, $color); // Restore transparency blending imagesavealpha($new_image, true); } // copy the old image to the new image (in memory, not the file!) imagecopyresampled($new_image, $old_image, 0, 0, 0, 0, $this->width->getValue(), $this->height->getValue(), $oldWidth, $oldHeight); if ($this->sourceType->getValue() == 'png' && $config->get('cms.images.perserve.png')) { imagepng($new_image); } else { imagejpeg($new_image, null, 100 * $this->quality->getValue()); } $this->cache($new_image); imagedestroy($old_image); imagedestroy($new_image); } } }
/** * Setter for the unit MAX duration. * * @param int $duration The desired duration in seconds. * * @since 1.0 */ public function setUnitMAXDuration($duration) { self::$logger->debug('>>setUnitMAXDuration(duration=[' . $duration . '])'); $this->unitMAXDuration->setValue($duration); self::$logger->debug('<<setUnitMAXDuration'); }
/** * Used to get the current DEnum item string value. * * @return string * * @since 1.0 */ public function getDisplayValue() { // check to see if the options have already been loaded from the DB if (empty($this->options)) { $this->getOptions(); } $val = Integer::zeroPad($this->value); if (isset($this->options[$val])) { return $this->options[$val]; } else { return 'Unknown'; } }
/** * Testing the zeroPad method. * * @since 1.2.1 */ public function testZeroPad() { $val = Integer::zeroPad(25); $this->assertEquals('00000000025', $val, 'Testing the zeroPad method'); }