<span class="help-box"><?php _e('Uploaded images will be saved in JPG/JPEG format, it saves space but images will not have transparent background.'); ?> </span> </div> </div> </div> <div class="form-row"> <div class="form-label"><?php _e('Force aspect'); ?> </div> <div class="form-controls"> <div class="form-label-checkbox"> <input type="checkbox" id="force_aspect_image" name="force_aspect_image" value="1" <?php echo osc_force_aspect_image() ? 'checked="checked"' : ''; ?> /> <label for="force_aspect_image"><?php _e('Force image aspect.'); ?> </label> <span class="help-box"><?php _e('No white background will be added to keep the size.'); ?> </span> </div> </div> </div> <div class="form-row"> <div class="form-label"><?php
public function resizeTo($width, $height, $force_aspect = null, $upscale = true) { if ($force_aspect == null) { $force_aspect = osc_force_aspect_image(); } if ($this->_width / $this->_height >= $width / $height) { if ($upscale) { $newW = $width; } else { $newW = $this->_width > $width ? $width : $this->_width; } $newH = ceil($this->_height * ($newW / $this->_width)); if ($force_aspect) { $height = $newH; } } else { if ($upscale) { $newH = $height; } else { $newH = $this->_height > $height ? $height : $this->_height; } $newW = ceil($this->_width * ($newH / $this->_height)); if ($force_aspect) { $width = $newW; } } if (osc_use_imagick()) { $bg = new Imagick(); if ($this->ext == 'jpg') { $bg->newImage($width, $height, 'white'); } else { $bg->newImage($width, $height, 'none'); } $this->im->thumbnailImage($width, $height, true); $bg->compositeImage($this->im, imagick::COMPOSITE_OVER, floor(($width - $newW) / 2), floor(($height - $newH) / 2)); $this->im = $bg; } else { $newIm = imagecreatetruecolor($width, $height); imagealphablending($newIm, false); $colorTransparent = imagecolorallocatealpha($newIm, 255, 255, 255, 127); imagefill($newIm, 0, 0, $colorTransparent); imagesavealpha($newIm, true); imagecopyresampled($newIm, $this->im, floor(($width - $newW) / 2), floor(($height - $newH) / 2), 0, 0, $newW, $newH, $this->_width, $this->_height); imagedestroy($this->im); $this->im = $newIm; } $this->_width = $width; $this->_height = $height; return $this; }