Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4257
Latest: Alex998.
New This Month: 1
New This Week: 0
New Today: 0
Stats
Total Posts: 43295
Total Topics: 7523
Most Online Today: 159
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 144
Total: 144

Author Topic: Category image resizing doesn't work as well as with Posted pictures  (Read 7616 times)

0 Members and 1 Guest are viewing this topic.

Offline Scy

  • Member
  • *
  • Posts: 17
    • View Profile
Hi,

...and thank you for your excellent gallery. I recently installed Lite-version and almost instantly bought the Pro version, because of Lite's limited functions.

Anyways, I have a problem: I noticed that on my server images that are downloaded in different formats are resized correctly and thumbnails are generated as they should be. But I encountered following problems:

1. When I try to upload an category image in for newly created category, thumbnail isn't resized at all. This is though not very big problem, because I can resize it myself or use link for already resized pic.

BUT the second problem emerged:

2. When my user tries to create an own category inside his/her own gallery and tries to upload a category picture (even in JPEG format), it will be resized but for some reason it's colours get very distorted and you really cannot tell what picture itself resembles.

The problem no. 2 could be a server issue, but because automatic thumbnail resizing works flawlessy with every other images, I started to study about this.

It seems that thumbnails for normal pictures that are uploaded in the gallery are resized with function "generateThumbnail" that is found on file Gallery.php located in Sources folder:

Code: [Select]
function generateThumbnail($src_file, $dest_file, $width = 120, $height = 78)
{
global $gd2;
//Inspired by createThumbnail from SMF 1.1

//Check if Image Magik is installed
$IM_Installed = function_exists('NewMagickWand');

//Check if GD is installed
$GD_Installed = function_exists('imagecreate');

//If not Image Magick or GD installed return false
if ($IM_Installed == false && $GD_Installed == false)
return false;

//Check if GD2 is installed if we are lucky. (used by resizeImage)
if(!$IM_Installed)
$gd2 =  function_exists('imagegd2');

//Increase the allowed time in case of large image
@ini_set('max_execution_time', '300');
@ini_set('memory_limit', '32M');

//Image/Media type extensions
$extensions = array('1' => 'gif', '2' => 'jpeg','3' => 'png','4' => 'swf','5' => 'psd',
'6' => 'bmp','7' => 'tiff','8' => 'tiff','9' => 'jpc','10' => 'jp2', '11' => 'jpx',
'12' => 'jb2','13' => 'swc','14' => 'iff','15' => 'wbmp','16' => 'xbm');

//Get image size if it is a picture...Mainly need to get format of picture
$size = getimagesize($src_file);

//Could not get size information on the picture
if(empty($size))
return false;

//Set the thumbnail flag
$good = false;
//Still in testing phase
$IM_Installed = false;
//Use Image Magik over GD if possible
if(!$IM_Installed)
{
//Use GD Lib

//Check if the file is a gif and see if it supports imagecreatefromgif which isn't always in GD
if($extensions[$size[2]] == 'gif' && !function_exists('imagecreatefromgif') && function_exists('imagecreatefrompng'))
{
//Use SMF functions by Yamasoft for loading gif
$img = gif_loadFile($src_file);
//and converting to a png
gif_outputAsPng($img, $dest_file);

if ($image = imagecreatefrompng($dest_file))
{
//Get the width and height of the image
$img_width = imagesx($image);
$img_height = imagesy($image);
//Finaly resize the image and give us our thumbnail
resizeImage($image, $dest_file, $img_width, $img_height, $width, $height);
//Set flag that thumbnail ok
$good = true;
}

}
else
{

//Use GD's built image create functions for this image.
if(function_exists('imagecreatefrom' . $extensions[$size[2]]))
{
$imagecreatefrom = 'imagecreatefrom' . $extensions[$size[2]];
if ($image = $imagecreatefrom($src_file))
{
//Get the width and height of the image
$img_width = imagesx($image);
$img_height = imagesy($image);
//Finaly resize the image and give us our thumbnail
resizeImage($image, $dest_file, $img_width, $img_height, $width, $height);
//Set flag that thumbnail ok
$good = true;
}
}
}

}
else
{
//Use Image Magik
$wand = NewMagickWand();
//Load the image
@MagickReadImage($wand,$src_file);
//Resize the image
@MagickResizeImage($wand, $width, $height, THUMBNAIL_FILTER, THUMBNAIL_BLUR);
//Set the filename before we write it
@MagickSetFilename($wand,$dest_file);
//Write the resized image
if(MagickWriteImage($wand,$dest_file))
$good = true;

//Free resources
DestroyMagickWand($wand);

//Wow that was easy! Compare that with the amount of lines for GD!!!!
}


//Check if we were able to create the thumbnail
if($good)
return true;
else
{
//Delete the file if we failed
@unlink($dest_file);
//No thumbnail made :(
return false;
}

}

This code seems to be similar (as it states) like in the SMF 1.1's own thumbnail resizing function.

In addition to this, SMF Gallery Pro's user's own galleries has a different kind of function for resizing the gallery gategory picture that is uploaded when creating the new user's own category. This function is called "DoCatImageResize" and it's located in ../Sources/UserGallery.php

Code: [Select]
function DoCatImagResize($sizes,$destName)
{
global $modSettings,$gd2;

$default_formats = array(
'1' => 'gif',
'2' => 'jpeg',
'3' => 'png',
'6' => 'bmp',
'15' => 'wbmp'
);

// Gif? That might mean trouble if gif support is not available.
if ($sizes[2] == 1 && !function_exists('imagecreatefromgif') && function_exists('imagecreatefrompng'))
{
// Download it to the temporary file... use the special gif library... and save as png.
if ($img = @gif_loadFile($destName) && gif_outputAsPng($img, $destName))
$sizes[2] = 3;
}
// A known and supported format?
if (isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
{
$imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
if ($src_img = @$imagecreatefrom($destName))
{




resizeImage($src_img, $destName, imagesx($src_img), imagesy($src_img), $modSettings['gallery_set_cat_width'], $modSettings['gallery_set_cat_height']);
}
}
}

It seems that there are some differences between these two codes and in addition to greater support of image  types, it seems that latter doesn't work properly on my server (It doesn't resize GIF images at all and JPEG images gets distorted).

I even tried to modificate the latter version to work similarry as the first one, but with my limited programming skills I failed.

So my question is - would it be possible that you (as the creator of this excellent modification) could provide me modificated code that I could replace the function DoCatImagResize to make it work as good as the function generateThumbnail? It seems that you have forgotten to update this latter function DoCatImagResize when developing the first one.

It would be also excellent if point 1 mentioned in the beginning of this post could be fixed with small modification.

And PS. I really hope that you could give me the direct code, because I have made many other modifications to code too, so uninstalling and updating it is not possible (or at least, in generally, it is an ernomous process.)

I also have some other improvement suggestion for this excellent script but I'll be putting them later on proper threads on this forum.

Thank you!  ;)

« Last Edit: September 04, 2007, 09:21:06 am by Scy »

Offline Scy

  • Member
  • *
  • Posts: 17
    • View Profile
Re: Category image resizing doesn't work as well as with Posted pictures
« Reply #1 on: September 04, 2007, 10:42:47 am »
In addition, here's an screenshot of User's gallery where first gallery section pic is uploaded originally from full colour JPEG image with very vivid colors (and the result is nearly blue image).

Second one is BMP and third GIF image, both seems to work resize fine with proper colours.

It seems that there is some kind of incompatibility with resizing commands latter function uses in my server because JPEG is resulting as shown in the screenshot. Allthough other thumbnailing works just fine with first function.

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16452
    • View Profile
Re: Category image resizing doesn't work as well as with Posted pictures
« Reply #2 on: September 04, 2007, 07:17:40 pm »
What version of SMF are you running?

1. Resizing for normal image categories not added yet.

2. The quality is probably becuase of a missing global $gd2
For the following two functions UserEditCategory2(), and UserAddCategory2() if it is added that should fix that problem for all newly uploaded images.

generateThumbnail funciton is only used if you are using SMF 1.0.x its a replacement since createthumbnail does not exist in SMF 1.0.x


« Last Edit: September 04, 2007, 07:35:00 pm by SMFHacks »
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline Scy

  • Member
  • *
  • Posts: 17
    • View Profile
Re: Category image resizing doesn't work as well as with Posted pictures
« Reply #3 on: September 05, 2007, 03:45:12 am »
Quote
What version of SMF are you running?

New one, SMF 1.1.3

Quote
1. Resizing for normal image categories not added yet.

Ok.

Quote
2. The quality is probably becuase of a missing global $gd2
For the following two functions UserEditCategory2(), and UserAddCategory2() if it is added that should fix that problem for all newly uploaded images.

Excellent! I added that to botch functions and it really fixed the problem. Thank you! ;)

Quote
generateThumbnail funciton is only used if you are using SMF 1.0.x its a replacement since createthumbnail does not exist in SMF 1.0.x

Oh, ok!

 

Related Topics

  Subject / Started by Replies Last post
2 Replies
4400 Views
Last post February 19, 2007, 06:31:58 pm
by GgAcE
0 Replies
4389 Views
Last post August 27, 2007, 07:06:29 am
by Blue Steel
2 Replies
4749 Views
Last post October 15, 2007, 07:32:45 pm
by merosler
12 Replies
10099 Views
Last post August 23, 2009, 07:41:43 pm
by SMFHacks
6 Replies
6543 Views
Last post January 13, 2014, 06:03:34 am
by Cmely

+- Recent Topics

Please Help! by SMFHacks
April 17, 2024, 08:04:55 am

Rate own images by fvlog19
April 11, 2024, 10:56:53 am

Tidy Child Boards on 2.1.4 by SMFHacks
April 04, 2024, 03:54:12 pm

Problems SMF 2.0.19 > 2.1.4 SMF Gallery Pro - Recents Images to overall header by Michel68
March 30, 2024, 12:41:08 pm

Can't DROP 'id_member'; check that column/key exists Datei: by SMFHacks
March 30, 2024, 11:58:20 am

No thumbnails on new uploads by Tonyvic
March 29, 2024, 06:26:18 am

Display the Contact Page for guests by SMFHacks
March 27, 2024, 10:55:43 am

is it possible to add support for odysee.com by fvlog19
March 21, 2024, 08:47:51 am

Request for admin notification by davejo
March 10, 2024, 01:31:59 am

I need help with torrent upload by Ineedsmfhelp
March 09, 2024, 10:01:13 pm

Powered by EzPortal