avatar autoresize

Looking for an Extension? Have an Extension request? Post your request here for help. (Note: This forum is community supported; while there is an Extensions Development Team, said team does not dedicate itself to handling requests in this forum)
Scam Warning
User avatar
SalazarAG
Registered User
Posts: 677
Joined: Mon Mar 30, 2015 10:48 am

Re: avatar autoresize

Post by SalazarAG »

josegf wrote:I created a solution, I hope this helps you.

You'll need PHP 5.5 in your server and PHP GD library. (Probably you have, it's very common config many wordpress theme uses PHP GD library)

Then you need to edit includes/functions_upload.php, locate a function called "move_file"

Before this function you need to add the following code:

Code: Select all

	function resize_image($file, $w, $h, $crop=FALSE)
	{
		list($width, $height) = getimagesize($file);
		$r = $width / $height;
		if ($crop) {
			if ($width > $height) {
				$width = ceil($width-($width*abs($r-$w/$h)));
			} else {
				$height = ceil($height-($height*abs($r-$w/$h)));
			}
			$newwidth = $w;
			$newheight = $h;
		} else {
			if ($w/$h > $r) {
				$newwidth = $h*$r;
				$newheight = $h;
			} else {
				$newheight = $w/$r;
				$newwidth = $w;
			}
		}
		if($this->extension == "jpg") $src = imagecreatefromjpeg($file);
		if($this->extension == "png") $src = imagecreatefrompng($file);
		$dst = imagecreatetruecolor($newwidth, $newheight);
		imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
		if($this->extension == "jpg") imagejpeg($dst,$file);
		if($this->extension == "png") imagepng($dst,$file);
	}
then in the move_file function locate the following code:

switch ($upload_mode)

just before this insert this code:

Code: Select all

$this->resize_image($this->filename,$this->upload->max_width,$this->upload->max_height);
And that's all :)

P.D. Please if you distribute/post this solution, please just mention me, thanks.

Cheers (ツ)
Jose A. Gallardo
Twitter: @Gallardo4Code
Hello josegf!

My forum is localhost and the web server that I have the 5.4.16 version of PHP :(

I can not test as it tried to update the web server to a higher version and Apache no longer worked :(
I'm sorry for my English. Google Translator does a bad job. :D
josegf
Registered User
Posts: 9
Joined: Mon Jan 12, 2015 7:59 pm

Re: avatar autoresize

Post by josegf »

Hi Salazar,

I think PHP version not so important, just GD and you have it, so Yes, I think so you can try this solution.

Cheers (ツ)
Jose A. Gallardo
Twitter: @Gallardo4Code
User avatar
SalazarAG
Registered User
Posts: 677
Joined: Mon Mar 30, 2015 10:48 am

Re: avatar autoresize

Post by SalazarAG »

josegf wrote:Hi Salazar,

I think PHP version not so important, just GD and you have it, so Yes, I think so you can try this solution.

Cheers (ツ)
Jose A. Gallardo
Twitter: @Gallardo4Code
Hello again, Jose! :)

I followed the steps.

Something does not seem to work. Resizing worked, but is maintained image proportions. :(

I set the avatar settings for: 150x150 maximum and minimum 150x150, and from that the proportions are maintained, the cut is not done.

What am I doing wrong? I would have to add the height, width and cut in the code that you passed?
I'm sorry for my English. Google Translator does a bad job. :D
josegf
Registered User
Posts: 9
Joined: Mon Jan 12, 2015 7:59 pm

Re: avatar autoresize

Post by josegf »

Hi Salazar

I don't understand your question. don't you want image proportions? do you prefer deform the image? or what?

Cheers (ツ)
Jose A. Gallardo
Twitter: @Gallardo4Code
User avatar
SalazarAG
Registered User
Posts: 677
Joined: Mon Mar 30, 2015 10:48 am

Re: avatar autoresize

Post by SalazarAG »

josegf wrote:Hi Salazar

I don't understand your question. don't you want image proportions? do you prefer deform the image? or what?

Cheers (ツ)
Jose A. Gallardo
Twitter: @Gallardo4Code
Sorry it was not clear, is that translator use because I am from Brazil and my English is bad hahaha

I will try to illustrate.

I sent a picture of 1024x768 pixels. She has been resized to 150x113 pixels. He maintained the ratio of width. I do not want proportions, I want to exact dimensions.

What I wish is that the image is in the exact dimensions of 150x150 pixels, for this cropping the image edges automatically.

I do not know if it was clear even sorry for my english haha
I'm sorry for my English. Google Translator does a bad job. :D
josegf
Registered User
Posts: 9
Joined: Mon Jan 12, 2015 7:59 pm

Re: avatar autoresize

Post by josegf »

Sorry it was not clear, is that translator use because I am from Brazil and my English is bad hahaha
Hahaha no problem buddy, my native language is spanish, I know how you feel.

Ok, so you want to deform the picture to fit 150x150, ok?

So, you have two options, the easy (and best one) it's to set crop parameter to true:

Code: Select all

$this->resize_image($this->filename,$this->upload->max_width,$this->upload->max_height, TRUE);
the other one it's to modify the resize function to force resize.

Code: Select all


function resize_image($file, $w, $h)
   {
      list($width, $height) = getimagesize($file);
      if($this->extension == "jpg") $src = imagecreatefromjpeg($file);
      if($this->extension == "png") $src = imagecreatefrompng($file);
      $dst = imagecreatetruecolor($w, $h);
      imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height);
      if($this->extension == "jpg") imagejpeg($dst,$file);
      if($this->extension == "png") imagepng($dst,$file);
   }

Select the one you prefer.

Cheers (ツ)
Jose A. Gallardo
Twitter: @Gallardo4Code
User avatar
SalazarAG
Registered User
Posts: 677
Joined: Mon Mar 30, 2015 10:48 am

Re: avatar autoresize

Post by SalazarAG »

josegf wrote:
Sorry it was not clear, is that translator use because I am from Brazil and my English is bad hahaha
Hahaha no problem buddy, my native language is spanish, I know how you feel.

Ok, so you want to deform the picture to fit 150x150, ok?

So, you have two options, the easy (and best one) it's to set crop parameter to true:

Code: Select all

$this->resize_image($this->filename,$this->upload->max_width,$this->upload->max_height, TRUE);
the other one it's to modify the resize function to force resize.

Code: Select all


function resize_image($file, $w, $h)
   {
      list($width, $height) = getimagesize($file);
      if($this->extension == "jpg") $src = imagecreatefromjpeg($file);
      if($this->extension == "png") $src = imagecreatefrompng($file);
      $dst = imagecreatetruecolor($w, $h);
      imagecopyresampled($dst, $src, 0, 0, 0, 0, $w, $h, $width, $height);
      if($this->extension == "jpg") imagejpeg($dst,$file);
      if($this->extension == "png") imagepng($dst,$file);
   }

Select the one you prefer.

Cheers (ツ)
Jose A. Gallardo
Twitter: @Gallardo4Code
Google translator in then saving hahaha

I did a quick test with the first option you spent and not enjoying it because picture with 1500x2000 pixels (example) is very wrinkled. The latter i can determine the size of the cuts on the sides?
I'm sorry for my English. Google Translator does a bad job. :D
josegf
Registered User
Posts: 9
Joined: Mon Jan 12, 2015 7:59 pm

Re: avatar autoresize

Post by josegf »

So, if you don't like the crop, I recommend for you the second option, modify the resize function. :)
User avatar
SalazarAG
Registered User
Posts: 677
Joined: Mon Mar 30, 2015 10:48 am

Re: avatar autoresize

Post by SalazarAG »

josegf wrote:So, if you don't like the crop, I recommend for you the second option, modify the resize function. :)
So I prefer the second it. Thank you for help, it fell from heaven hahaha :)

In that part of the file insert the second option code?
I'm sorry for my English. Google Translator does a bad job. :D
josegf
Registered User
Posts: 9
Joined: Mon Jan 12, 2015 7:59 pm

Re: avatar autoresize

Post by josegf »

Just replace the resize function with the new one :)
hasanmak
Registered User
Posts: 8
Joined: Wed Mar 25, 2015 8:42 am

Re: avatar autoresize

Post by hasanmak »

Not practical to save avatar for phpBB (2, 3, 3.1 ) :(
Must be Automatic resize and cutting options.
User avatar
made
Registered User
Posts: 56
Joined: Sun Jan 11, 2009 4:49 pm

Re: avatar autoresize

Post by made »

José (josegf), after a long search I came across your solution to automatically resize avatars. It works like a charm! Thank you so much!!!

Have you ever released it as an extension? I'm sure it would come in very handy for many board admins :D

P.S: Now I'm having trouble with image attachments :? I tried to attach an image and this is what I get an empty error message. I guess the message must be related to the size of the image or something like that. What can I do to fix this!!!
User avatar
Zaishen
Registered User
Posts: 199
Joined: Sat Dec 18, 2010 6:08 am

Re: avatar autoresize

Post by Zaishen »

any news on this? come one geeks, make it posible
User avatar
Elias
Registered User
Posts: 5152
Joined: Sat Feb 25, 2006 4:31 pm
Name: Elias

Re: avatar autoresize

Post by Elias »

Haven't read the whole topic but have a look at this extension:
viewtopic.php?f=456&t=2343741

Thanks
"Mystery creates wonder, and wonder is the basis of man's desire to understand." - Neil Armstrong
|Installing Extensions|Writing Extensions|Extension Validation Policy|
User avatar
Zaishen
Registered User
Posts: 199
Joined: Sat Dec 18, 2010 6:08 am

Re: avatar autoresize

Post by Zaishen »

Elias wrote:Haven't read the whole topic but have a look at this extension:
viewtopic.php?f=456&t=2343741

Thanks
thats not something stable and i dont understand how works, i think is to complicated, sofisticated things sucks..

what we are looking for is an simple infusion wich make the avatars to upload with no problems if the sizes of the images are big, for example mybb is auto resizing the avatars no metter if is 2000 x 1920 or 120 x 90, the script makes the avatars to resize to the size u have given inside acp

we dont want to get this errors on avatar change:

The avatar’s filesize must be between 0 and 6 KiB.

The submitted avatar is 184 pixels wide and 184 pixels high. Avatars must be at least 20 pixels wide and 20 pixels high, but no larger than 90 pixels wide and 90 pixels high.

phpbb devs should make this problem solved in future phpbb versions
Post Reply

Return to “Extension Requests”