• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

How does the image parser work?

Jaxel

Well-known member
#2
GOT IT! wow this was so much easier than vBulletin! This is how to do it... feel free to use in your own mods!

Code:
	// get extension of image
	$extension = XenForo_Helper_File::getFileExtension($input['media_thumb']);

	// get width, height and type of image
	$imageInfo = @getimagesize($input['media_thumb']);

	// set target save location
	$targetloc = XenForo_Helper_File::getInternalDataPath().'/media/1.'.$extens;

	// create image object from existing image
	if ($image = XenForo_Image_Abstract::createFromFile($input['media_thumb'], $imageInfo[2]))
	{
		// resize image object to 160 width
		$image->thumbnail('160');

		// get image height and determine its distance from 90
		$height = $image->getHeight();
		$offset = ($height - 90) / 2;

		// crop image height to 90 from center, extend if shorter
		$image->crop('0', $offset, '160', '90');

		// save thumbnail image to target location
		$image->output($imageInfo[2], $targetloc);
	}
 

Jaxel

Well-known member
#3
If you wanted... you could force a JEPG file type for your thumbnails... (you could do the same with GIF and PNG)

Code:
		$targetLoc = XenForo_Helper_File::getInternalDataPath().'/media/1.jpg';
		$imageInfo = @getimagesize($input['media_thumb']);

		if ($image = XenForo_Image_Abstract::createFromFile($input['media_thumb'], $imageInfo[2]))
		{
			$image->thumbnail('160');

			$height = $image->getHeight();
			$offset = ($height - 90) / 2;

			$image->crop('0', $offset, '160', '90');
			$image->output(IMAGETYPE_JEPG, $targetLoc);
		}
 

Jamie

Well-known member
#4
I know this is Off Topic, but I have noticed a trend... You REALLY like working with xF don't you? :D

People like myself appreciate the work you do and it's great and very helpful, but I get a kick out of it when you're asking a question and figure it out and then find out it's easier than vB..

If I only knew how to code... so I could have some fun! :)

Jamie
 

Jaxel

Well-known member
#5
Yes... I'm loving XenForo... I'm not happy with having to rewrite my Media Library mod... but cesta la vie...

But it appears that the /internal_data/ path isn't accessable from the browser...

Does anyone know an alternative to getInternalDataPath for the regular data path?
 

Kier

XenForo Developer
Staff member
#6
Yes... I'm loving XenForo... I'm not happy with having to rewrite my Media Library mod... but cesta la vie...

But it appears that the /internal_data/ path isn't accessable from the browser...

Does anyone know an alternative to getInternalDataPath for the regular data path?
Beta 3 exposes it. Prior to that, no.
 

Jaxel

Well-known member
#9
The external data path is always expressed as a relative URL from the base path.
XenForo_Helper_File::getInternalDataPath() will return "/home/path/to/website/data" for me... thats not an URL, thats a PATH... I want to be able to get xen1.8wayrun.com/data in a variable automatically... since I know people can change the location of their data folder.
 

Jaxel

Well-known member
#11
You asked for the external path / URL.
Yes... the external URL... by default its yourwebsite.com/data

However, in the config, you can change the external data path to something else... its why you guys created the getExternalDataPath function. However, in my templates I am hardcoding "data/" as the external data URL... is there a way to automatically get the external data URL, the same way that getExternalDataPath gets the external data PATH?
 

Kier

XenForo Developer
Staff member
#12
XenForo_Helper_File::getExternalDataPath() will always return a realtive path to the base URL, so it can be combined with the base URL to form an absolute URL, or used on its own as a relative URL. Either way, it can be used as a URL within your templates.
 

Jaxel

Well-known member
#13
XenForo_Helper_File::getExternalDataPath() will always return a realtive path to the base URL, so it can be combined with the base URL to form an absolute URL, or used on its own as a relative URL. Either way, it can be used as a URL within your templates.
Okay... how would I use this in combination with the base url? Is there a function to get the base url?

If I use getExternalDataPath by itself, I NEVER get a relative path, it ALWAYS gives me the full path from root.
 

Kier

XenForo Developer
Staff member
#14
Aaaah, sorry, I'm talking crap. You actually want XenForo_Application::$externalDataPath - that is the relative path.
 

Jaxel

Well-known member
#15
Aaaah, sorry, I'm talking crap. You actually want XenForo_Application::$externalDataPath - that is the relative path.
Thanks... now how do I get the base url? I tried this:

Code:
$external = XenForo_Link::buildPublicLink('full:'.XenForo_Application::$externalDataPath.'/media');
works... but I think there should be a better way...
 

Kier

XenForo Developer
Staff member
#17
Thanks... now how do I get the base url? I tried this:

Code:
$external = XenForo_Link::buildPublicLink('full:'.XenForo_Application::$externalDataPath.'/media');
works... but I think there should be a better way...
If you're working from within the XenForo template system, there is no need for anything else, the base URL is already in place.

Assuming that you pass the value of XenForo_Application::$externalDataPath out via the $viewParams in your public controller, you can simply link to it directly - ie:
PHP:
return $this->responseView('My_ViewPublic_Something', 'some_template', array(
 'dataPath' => XenForo_Application::$externalDataPath));
HTML:
<a href="{$dataPath}/path/to/something">Something</a>
Or am I missing something here? If so, what exactly are you trying to achieve?[/php]