Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 05-06-2010, 11:41 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default How does the Image Class Work?

So I want to take an image... which is 4:3... resize it, and then crop it to 16:9. I know how to do this using GD2, but sadly it doesnt work with ImageMagick. So now I'm trying to use the existing image classes in VB to handle it... but I can't get them working either...
Code:
require_once(DIR . '/includes/class_image.php');
$image =& vB_Image::fetch_library();
$image->fetch_thumbnail($filename, $location, $newWidth, $newHeight, $quality);
Doesnt seem to do anything...

--------------- Added [DATE]1273196508[/DATE] at [TIME]1273196508[/TIME] ---------------

This is what I am using now...

Code:
if ($vbulletin->options['imagetype'] == 'GD')
{
	$newImage = imagecreatetruecolor(160, 90);
	$oldImage = imagecreatefromjpeg($target);
	imagecopyresampled($newImage, $oldImage, 0, 0, 0, $offHeight, $newWidth, $newHeight, $oldWidth, $oldHeight);
	unlink($target);
	imagejpeg($newImage, $target, $quality);
}

/*
if ($vbulletin->options['imagetype'] == 'Magick')
{
	$thumb = new Imagick($target);
	$thumb->cropThumbnailImage($newWidth,$newHeight);
	$thumb->writeImage($target);
	$thumb->destroy();
}
*/

The second set is commented out, because I can't get it working... Either I need to figure out how to do this with the built in image classes... or I need to figure out how to do this with the imagick class... I can't figure out either.
Reply With Quote
  #2  
Old 05-09-2010, 03:49 AM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So anyone got any ideas?
Reply With Quote
  #3  
Old 05-12-2010, 09:00 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So absolutely no one knows how the image class works?

All I want to do is take an image, crop from center and resize.
Reply With Quote
  #4  
Old 05-17-2010, 08:52 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

So yeah... bumping once again... Need to either get the image class working, or figure out how to resize an image using ImageMagick...
Reply With Quote
  #5  
Old 07-19-2010, 02:52 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Bump..........
Reply With Quote
  #6  
Old 07-19-2010, 02:59 PM
Guest190829
Guest
 
Posts: n/a
Default

What do you mean it's not working? Are you getting errors?
Reply With Quote
  #7  
Old 07-19-2010, 07:50 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Which part are you talking about? The ImageMagick code doesn't work as it just sends me to a blank white page (stops processing code) and doesn't write any image to the $target file. The Image Class code doesn't work because its obviously incomplete and there isn't even a write step anywhere in the code. So I need to either find out why the ImageMagick code doesn't work, or complete the image class code. But the VB4 image class is obfuscated to all hell, so who knows what the hell is going on in those files.
Reply With Quote
  #8  
Old 07-19-2010, 08:27 PM
Guest190829
Guest
 
Posts: n/a
Default

What is the returned value of $image->fetch_thumbnail() ?

Also, I'm not very familiar with vB's image class, but from the looks of it, it doesn't handle actually uploading the file. This is a good thing. You'll probably have to use vB's file class to upload it to your server.
Reply With Quote
  #9  
Old 07-20-2010, 03:19 PM
Jaxel Jaxel is offline
 
Join Date: Sep 2005
Posts: 1,160
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Which is the purpose of this thread...

I have no idea how to write a thumbnail using the VB image class. According to vB_Image_Abstract fetch_thumbnail creates the actual thumbnail, but I don't know what to do next. The VB upload class is even more confusing than the VB image class; and neither are well documented.

Let me explain my function... It takes in 2 variables, the first one is a URL to an image; the second is the ID where it will be stored.

Code:
function build_thumbnail($thumbnail, $mediaID)
{
	global $vbulletin;

	require_once(DIR . '/includes/class_vurl.php');
	$vurl = new vB_vURL($vbulletin);
	$vurl->set_option(VURL_URL, $thumbnail);
	$vurl->set_option(VURL_RETURNTRANSFER, 1);
	$vurl->set_option(VURL_FOLLOWLOCATION, 1);
	$vurl->set_option(VURL_TIMEOUT, 30);
	$result = $vurl->exec();

	$target = DIR.'/'.$vbulletin->options['media_thumb_dir'].'/thumbs/'.$mediaID.'.jpg';

	$file = fopen($target, 'wb');
	fwrite($file, $result);
	fclose($file);

	preg_match('#(.*/)(.*)$#i',$target,$matches);
	$location = $matches[1];
	$filename = $matches[2];

	$newRatio = 90 / 160;
	$newWidth = 160;
	$newHeight = $newRatio * $newWidth;
	$quality = $vbulletin->options['media_thumb_quality'];

	require_once(DIR . '/includes/class_image.php');
	$image =& vB_Image::fetch_library($vbulletin);
	$thumb = $image->fetch_thumbnail($filename, $location, $newWidth, $newHeight, $quality);
	print_r($thumb);
	exit;
}
As you can see, its pretty simple.

first it gets the image information using VB's built in cURL
then it uses fwrite to write the $result to $target
then it gets the location and filename of the file it just wrote to edit it
then it defines crop variables, width, height and quality
Then it should generate a thumbnail using VB's image class...

However, print_r($thumb) outputs the following:

Code:
Array ( [filedata] => [filesize] => 0 [dateline] => 0 [imageerror] => )
Obviously something is getting lost.

--------------- Added [DATE]1279646313[/DATE] at [TIME]1279646313[/TIME] ---------------

However, I don't think it even matters, since the VB image class doesn't crop anything, which is essential for this. I should just use the two methods for GD and Imagick; but I can't get the Imagick function working.

Code:
function build_thumbnail($thumbnail, $mediaID)
{
	global $vbulletin;

	require_once(DIR . '/includes/class_vurl.php');
	$vurl = new vB_vURL($vbulletin);
	$vurl->set_option(VURL_URL, $thumbnail);
	$vurl->set_option(VURL_RETURNTRANSFER, 1);
	$vurl->set_option(VURL_FOLLOWLOCATION, 1);
	$vurl->set_option(VURL_TIMEOUT, 30);
	$result = $vurl->exec();

	$target = DIR.'/'.$vbulletin->options['media_thumb_dir'].'/thumbs/'.$mediaID.'.jpg';

	$file = fopen($target, 'wb');
	fwrite($file, $result);
	fclose($file);

	$newRatio = 90 / 160;
	$newWidth = 160;
	$newHeight = $newRatio * $newWidth;
	$quality = $vbulletin->options['media_thumb_quality'];

	if ($vbulletin->options['imagetype'] == 'GD')
	{
		list($oldWidth, $oldHeight) = getimagesize($target);
		$oldRatio = $oldHeight / $oldWidth;
		$tmpHeight = $oldRatio * $newWidth;
		$offHeight = ($oldHeight - ($newRatio * $oldWidth)) / 2;

		preg_match('#([\w]+)$#i',$thumbnail,$filetype);

		switch ($filetype[1])
		{
			case "jpg":		$oldImage = imagecreatefromjpeg($target);		break;
			case "png":		$oldImage = imagecreatefrompng($target);		break;
			case "gif":		$oldImage = imagecreatefromgif($target);		break;
		}

		$newImage = imagecreatetruecolor(160, 90);
		imagecopyresampled($newImage, $oldImage, 0, 0, 0, $offHeight, $newWidth, $tmpHeight, $oldWidth, $oldHeight);
		imagejpeg($newImage, $target, $quality);
	}

	if ($vbulletin->options['imagetype'] == 'Magick')
	{
		$thumb = new Imagick($target);
		$thumb->cropThumbnailImage($newWidth,$newHeight);
		$thumb->writeImage($target);
		$thumb->destroy();
	}
}
The GD2 function works GREAT... the Imagick function breaks with a white screen.
Reply With Quote
  #10  
Old 07-20-2010, 05:02 PM
Guest190829
Guest
 
Posts: n/a
Default

You have Image Magick installed on your server? (Let's get the easy questions out of the way first hehe)
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:14 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06609 seconds
  • Memory Usage 2,239KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (7)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete