Jump to content

Smf Gallery Edit


[dx]

Recommended Posts

Hi, I have installed SMF Forum with gallery, and I want make some changes.When I upload some image, example: 1024 x 768 it's uploaded in real format, and created thumbnail 190 x 143.Now I'm trying to add option to resize picture to 600 x 460 and create thumbnail.Here's code, and part which I've added is marked as red.

function AddPicture2(){	global $ID_MEMBER, $txt, $db_prefix, $modSettings, $sourcedir, $gd2;	isAllowedTo('smfgallery_add');	// Check if gallery path is writable	if (!is_writable($modSettings['gallery_path']))		fatal_error($txt['gallery_write_error'] . $modSettings['gallery_path']);	$title = htmlspecialchars($_REQUEST['title'],ENT_QUOTES);	$description = htmlspecialchars($_REQUEST['description'],ENT_QUOTES);	$keywords = htmlspecialchars($_REQUEST['keywords'],ENT_QUOTES);	$cat = (int) $_REQUEST['cat'];	@$allowcomments = $_REQUEST['allowcomments'];	// Check if pictures are auto approved	$approved = (allowedTo('smfgallery_autoapprove') ? 1 : 0);	// Allow comments on picture if no setting set.	if(empty($modSettings['gallery_commentchoice']) || $modSettings['gallery_commentchoice'] == 0)		$allowcomments = 1;	else	{		if(empty($allowcomments))			$allowcomments = 0;		else			$allowcomments = 1;	}	if (trim($title) == '')		fatal_error($txt['gallery_error_no_title'],false);	if (empty($cat))		fatal_error($txt['gallery_error_no_cat'],false);	$testGD = get_extension_funcs('gd');	$gd2 = in_array('imagecreatetruecolor', $testGD) && function_exists('imagecreatetruecolor');	unset($testGD);	//Process Uploaded file	if (isset($_FILES['picture']['name']) && $_FILES['picture']['name'] != '')	{		$sizes = getimagesize($_FILES['picture']['tmp_name']);		$failed = false;		if ($sizes === false)		{			@unlink($modSettings['gallery_path'] . '/img.tmp');			move_uploaded_file($_FILES['picture']['tmp_name'], $modSettings['gallery_path'] . '/img.tmp');					$_FILES['picture']['tmp_name'] = $modSettings['gallery_path'] . '/img.tmp';			$sizes = getimagesize($_FILES['picture']['tmp_name']);			$failed =true;		}			// No size, then it's probably not a valid pic.			if ($sizes === false)				fatal_error($txt['gallery_error_invalid_picture'],false);			elseif ((!empty($modSettings['gallery_max_width']) && $sizes[0] > $modSettings['gallery_max_width']) || (!empty($modSettings['gallery_max_height']) && $sizes[1] > $modSettings['gallery_max_height']))			{				//Delete the temp file				@unlink($_FILES['picture']['tmp_name']);				fatal_error($txt['gallery_error_img_size_height'] . $sizes[1] . $txt['gallery_error_img_size_width'] . $sizes[0],false);			}			else			{				//Get the filesize				$filesize = $_FILES['picture']['size'];				if(!empty($modSettings['gallery_max_filesize']) && $filesize > $modSettings['gallery_max_filesize'])				{					//Delete the temp file					@unlink($_FILES['picture']['tmp_name']);					fatal_error($txt['gallery_error_img_filesize'] . round($modSettings['gallery_max_filesize'] / 1024, 2) . 'kb',false);				}				//Filename Member Id + Day + Month + Year + 24 hour, Minute Seconds				//$extension = substr(strrchr($_FILES['picture']['name'], '.'), 1);				$extensions = array(					1 => 'gif',					2 => 'jpeg',					3 => 'png',					5 => 'psd',					6 => 'bmp',					7 => 'tiff',					8 => 'tiff',					9 => 'jpeg',					14 => 'iff',					);				$extension = isset($extensions[$sizes[2]]) ? $extensions[$sizes[2]] : '.bmp';											$filename = $ID_MEMBER . '_' . date('d_m_y_g_i_s') . '.' . $extension;				if ($failed == false)					move_uploaded_file($_FILES['picture']['tmp_name'], $modSettings['gallery_path'] . $filename);				else 					rename($_FILES['picture']['tmp_name'], $modSettings['gallery_path'] . $filename);				@chmod($modSettings['gallery_path'] . $filename, 0644);				//Create thumbnail				require_once($sourcedir . '/Subs-Graphics.php');								createThumbnail($modSettings['gallery_path'] . $filename, 190, 143);					list($width, $height) = getimagesize($filename);				$filename_rs = imagecreatetruecolor(600, 460);				$filename_im = imagecreatefromjpeg($filename);				imagecopyresampled($filename_rs, $filename_im, 0, 0, 0, 0, 600, 460, $width, $height);				imagejpeg($filename_rs, $filename, 100);					rename($modSettings['gallery_path'] . $filename . '_thumb',  $modSettings['gallery_path'] . 'thumb_' . $filename);				rename($modSettings['gallery_path'] . $filename,  $modSettings['gallery_path'] . $filename);				$thumbname = 'thumb_' . $filename;														@chmod($modSettings['gallery_path'] . $thumbname, 0644);				//Create the Database entry				$t = time();				db_query("INSERT INTO {$db_prefix}gallery_pic							(ID_CAT, filesize,thumbfilename,filename, height, width, keywords, title, description,ID_MEMBER,date,approved,allowcomments)						VALUES ($cat, $filesize,'$thumbname', '$filename', $sizes[1], $sizes[0], '$keywords','$title', '$description',$ID_MEMBER,$t,$approved, $allowcomments)", __FILE__, __LINE__);			// Update the SMF Shop Points			if (isset($modSettings['shopVersion'])) 				db_query("UPDATE {$db_prefix}members				 	SET money = money + " . $modSettings['gallery_shop_picadd'] . " 				 	WHERE ID_MEMBER = {$ID_MEMBER}				 	LIMIT 1", __FILE__, __LINE__);								//Redirect to the users image page.				if ($ID_MEMBER != 0)					redirectexit('action=gallery;sa=myimages;u=' . $ID_MEMBER);				else 					redirectexit('action=gallery;cat=' . $cat);			}	}	else		fatal_error($txt['gallery_error_no_picture']);}

My code:list($width, $height) = getimagesize($filename);$filename_rs = imagecreatetruecolor(600, 460);$filename_im = imagecreatefromjpeg($filename);imagecopyresampled($filename_rs, $filename_im, 0, 0, 0, 0, 600, 460, $width, $height);imagejpeg($filename_rs, $filename, 100); I've tried everything, read a lot of tutorials.. but can't get it.Regards.

Link to comment
Share on other sites

Well, OK, I found it. Sorry for postinglist($width, $height) = getimagesize($modSettings['gallery_path'] . $filename);$filename_rs = imagecreatetruecolor(600, 460);$filename_im = imagecreatefromjpeg($modSettings['gallery_path'] . $filename);imagecopyresampled($filename_rs, $filename_im, 0, 0, 0, 0, 600, 460, $width, $height);imagejpeg($filename_rs, $modSettings['gallery_path'] . $filename, 100);I forgot to put $modSettings['gallery_path'] .

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...