function CreateThumbnail($src_image = '', $del_src = false) { wpfb_loadclass('FileUtils'); $src_set = !empty($src_image) && file_exists($src_image); $tmp_src = $del_src; if (!$src_set) { if (file_exists($this->GetLocalPath())) { $src_image = $this->GetLocalPath(); } elseif ($this->IsRemote()) { // if remote file, download it and use as source $res = wpfb_call('Admin', 'SideloadFile', $this->GetRemoteUri()); $src_image = $res['file']; $tmp_src = true; } } if (!file_exists($src_image) || @filesize($src_image) < 3) { if ($tmp_src) { @unlink($src_image); } return; } $ext = trim($this->GetExtension(), '.'); $src_size = array(); if (!WPFB_FileUtils::FileHasImageExt($this->file_name) && !($src_set && WPFB_FileUtils::IsValidImage($src_image, $src_size))) { // check if valid image if ($tmp_src) { @unlink($src_image); } return; } $this->DeleteThumbnail(); // delete old thumbnail $thumb_size = (int) WPFB_Core::$settings->thumbnail_size; if ($thumb_size == 0) { if ($tmp_src) { @unlink($src_image); } return; } $thumb = WPFB_FileUtils::CreateThumbnail($src_image, $thumb_size); $success = !empty($thumb) && !is_wp_error($thumb) && is_string($thumb) && file_exists($thumb); if (!$src_set && !$success) { $this->file_thumbnail = null; } else { // fallback to source image WARNING: src img will be moved or deleted! if ($src_set && !$success) { $thumb = $src_image; } $this->file_thumbnail = basename(trim($thumb, '.')); // FIX: need to trim . when image has no extension if (!is_dir(dirname($this->GetThumbPath()))) { WPFB_Admin::Mkdir(dirname($this->GetThumbPath())); } if (!@rename($thumb, $this->GetThumbPath())) { $this->file_thumbnail = null; @unlink($thumb); } else { @chmod($this->GetThumbPath(), octdec(WPFB_PERM_FILE)); } } if ($tmp_src) { @unlink($src_image); } }