function generateAvatarGD($gdversion, $src_img, $srcWidth, $srcHeight, $dstWidth, $dstHeight, $quality, $location) { if ($srcWidth > $dstWidth || $srcHeight > $dstHeight) { $ratio = $srcWidth / $srcHeight; if ($dstWidth / $dstHeight > $ratio) { $dstWidth = $dstHeight * $ratio; } else { $dstHeight = $dstWidth / $ratio; } } else { $dstWidth = $srcWidth; $dstHeight = $srcHeight; } if ((int) $gdversion == 1) { $dst_img = imagecreate($dstWidth, $dstHeight); imagecopyresized($dst_img, $src_img, 0, 0, 0, 0, (int) $dstWidth, (int) $dstHeight, $srcWidth, $srcHeight); } else { $dst_img = imagecreatetruecolor($dstWidth, $dstHeight); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, (int) $dstWidth, (int) $dstHeight, $srcWidth, $srcHeight); } $tmpfile = tempnam(CKunenaPath::tmpdir(), "kn_"); imagejpeg($dst_img, $tmpfile, $quality); CKunenaFile::copy($tmpfile, $location); unlink($tmpfile); imagedestroy($dst_img); }
function version($file, $newpath, $newfile, $maxwidth = 800, $maxheight = 800, $quality = 70, $scale = CKunenaImage::SCALE_INSIDE) { require_once KUNENA_PATH_LIB . '/kunena.file.class.php'; // create upload directory if it does not exist $imageinfo = self::getProperties($file); if (!$imageinfo) { return false; } if (!CKunenaFolder::exists($newpath)) { if (!CKunenaFolder::create($newpath)) { return false; } } CKunenaFolder::createIndex($newpath); if ($imageinfo->width > $maxwidth || $imageinfo->height > $maxheight) { $image = new CKunenaImage($file); if ($image->getError()) { return false; } if ($quality < 1 || $quality > 100) { $quality = 70; } $options = array('quality' => $quality); $image = $image->resize($maxwidth, $maxheight, true, $scale); $type = $image->getType(); $temp = CKunenaPath::tmpdir() . '/kunena_' . md5(rand()); $image->toFile($temp, $type, $options); unset($image); if (!CKunenaFile::move($temp, $newpath . '/' . $newfile)) { unlink($temp); return false; } } else { if (!CKunenaFile::copy($file, $newpath . '/' . $newfile)) { return false; } } return true; }
function replaceImage($kunena_db, $option, $imageName, $OxP) { $app =& JFactory::getApplication(); $kunena_db =& JFactory::getDBO(); if (!$imageName) { $app->redirect(JURI::base() . "index2.php?option={$option}&task=browseImages"); return; } require_once KUNENA_PATH_LIB . DS . 'kunena.file.class.php'; // This function will replace the selected image with a dummy (OxP=1) or delete it if ($OxP == "1") { $filename = split("\\.", $imageName); $fileName = $filename[0]; $fileExt = $filename[1]; $ret = CKunenaFile::copy(KUNENA_PATH_UPLOADED . DS . 'dummy.' . $fileExt, KUNENA_PATH_UPLOADED . DS . 'images' . DS . $imageName); } else { $ret = CKunenaFile::delete(KUNENA_PATH_UPLOADED . DS . 'images' . DS . $imageName); //remove the database link as well if ($ret) { $kunena_db->setQuery("DELETE FROM #__fb_attachments where filelocation='%/images/" . $imageName . "'"); $kunena_db->query() or trigger_dberror("Unable to delete attachment."); } } if ($ret) { $app->enqueueMessage(_KUNENA_IMGDELETED); } $app->redirect(JURI::base() . "index2.php?option={$option}&task=browseImages"); }