• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ How-to (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

Share an image from another website, paste direct into chat

A collection of how-to's, submitted by users for other users!

Moderator: re*s.t.a.r.s.*2

Post a reply
10 posts • Page 1 of 1

Postby waiheke » Wed Oct 27, 2010 12:45 am

This removes the direct link, and displays the image, after resizing if necessary, down to 320 pixels height.
The height is arbitrary, you can change it of course (see the last code)

Open your src/pfcurlprocessing.php file

Look for this line:

Code: Select all
  // pad it with a space so we can match things at the start of the 1st line.
  $ret = ' ' . $text;

Immediately after it, paste:

Code: Select all
// look for a jpg, gif, or png reference
// if not found, carry on as normal
$pos = strpos($ret,"jpg") || $pos = strpos($ret,"JPG") || $pos = strpos($ret,"png") || $pos = strpos($ret,"PNG") || $pos = strpos($ret,"gif") || $pos = strpos($ret,"GIF");
if($pos === false) {

come down to:

Code: Select all
  // Remove our padding..
  $ret = substr($ret, 1);

Immediately after it, paste:
Code: Select all
   

} else {


// remove padding also
$ret = substr($ret, 1);
$ret = trim($ret);
list($height) = getimagesize($ret);
// make sure we do have an image
if ($height) {
// find details and adjust if need be
if ($height <= 320) {
$height=$height;
} else {
$height = 320;
}

$ret = '<img src="' .$ret. '" height="' .$height. '">';
}}

EDITED ^^^^^^^^^^^^ this last portion has been updated.
See the next post

Your next line, already there, will read:
Code: Select all
  return($ret);
}

Enjoy
:)
Last edited by waiheke on Thu Oct 28, 2010 10:47 am, edited 1 time in total.
waiheke
Member
 
Posts: 126
Joined: Sun Sep 12, 2010 4:33 pm
Top

Postby waiheke » Thu Oct 28, 2010 10:44 am

I have looked at the getimage size chunk above, and here's an update.

1. It works with the two other options i am using, Uploading an Image and Pasting, & having a Second Emoticon box
2. It also looks for sizes both in height and width, not just one-dimensionally (as above, height only)
3. Fixes the bug where the word 'gift' for example was being noticed, with the string 'gif' in it.

It focuses on height, as the most space grabbing, but also limits width.

Code: Select all
   } else {

// deal with emotes2 and uploaded images by ignoring, and focusing only on a string that ends with .jpg, .gif or .png
$q1 = substr($ret, -4);
$q2 = (($q1 === ".jpg") || ($q1 === ".png") || ($q1 === ".gif") || ($q1 === ".JPG") || ($q1 === ".GIF") || ($q1 === ".PNG") || ($q1 === "jpeg") || ($q1 === "JPEG"));
if (!$q2) {



$ret = substr($ret, 1);
$ret = trim($ret);
// get size
$imagespec = getimagesize($ret);
// larger than 320?
if (360 <= $imagespec[0]){
if (360 <= $imagespec[1]){
function imageResize($width, $height, $target) {
// portrait mode is the most space-grabbing
if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}
$width = round($width * $percentage);
$height = round($height * $percentage);
return " width="$width" height="$height"";
}
//reduced size
$size = imageResize($imagespec[0], $imagespec[1], 360);
}} else {
// inherited size
$size= NULL;
}
// process

$ret = "<img src=" .$ret.$size. " border=1>";
// end emote2 loop here
}
}

and as before, the next EXISTING line in your file will be:

Code: Select all
  return($ret);
}

The code is always tested before posting here
Enjoy

:)
Last edited by waiheke on Mon Nov 01, 2010 9:11 am, edited 1 time in total.
waiheke
Member
 
Posts: 126
Joined: Sun Sep 12, 2010 4:33 pm
Top

Postby bhootnath » Sun Nov 28, 2010 11:38 pm

it is working fine when the user posts just the link to an image but i am facing issue if the user has posted some text along with the image link.. or even a smiley with it.. also if the user has selected some custom color for himself.. that also seems to break it..

still trying to figure out the root cause as am not sure if something is wrong with this code or my patches as i have quite a lot of other customizations (/slap, /topic etc.) as well added to my chat instance.. have you tested for these conditions i have mentioned above...
bhootnath
Member
 
Posts: 13
Joined: Fri Nov 19, 2010 10:12 pm
Top

Postby waiheke » Sun Dec 05, 2010 7:59 am

Hmm
The initial code relies on the string starting with "http://(website)" and terminating with ".jpg" <-- or gif or whatever, as a signal that it's an image.

Can you duplicate the error yourself and then post the string that gets presented in the text box ?? The extra bits - the smiley and/or the text and/or the colour coding?

It sounds like the string needs to be trimmed at each end of the superfluous stuff.
That is to say, to look for the needle of straw in the haybale and then present just that needle of straw
waiheke
Member
 
Posts: 126
Joined: Sun Sep 12, 2010 4:33 pm
Top

Postby Index » Wed Apr 13, 2011 8:24 am

The was a problem when i use this code..
May be i did something wrong...

For the most of users write some text (link to picture ): http://www.someimg.com/img.gif it was post like
Code: Select all
 <span style="color: #008080">http://www.someimg.com/img.gif</span>

So you code :
Code: Select all
list($height) = getimagesize($ret);

- Wont work... because link to pic is inside tag <span>

I resolve this:

Code: Select all
  $pos = stripos($ret,".jpg") || $pos = stripos($ret,".png") || $pos = stripos($ret,".gif");
  if($pos === false)
{
..........
}
else
{
 
  $beg=stripos($ret,"http://");
  if($beg===false) $beg=stripos($ret,"www.");
  if($beg===false) $beg=stripos($ret,"ftp.");
  if($beg !== false)
  {
     $imgsrc='$beg='.$beg;
     $end = stripos($ret,".jpg");
     if($end ===false) $end = stripos($ret,".gif");
     if($end ===false) $end=stripos($ret,".png");
     if($end !== false)
     {
       $imgsrc=substr($ret,$beg,$end-$beg+4);
     }
  }
  if($imgsrc) $size = getimagesize($imgsrc);
   
    // make sure we do have an image
    if ($size)
    {
      $height = $size[1];
   
    // find details and adjust if need be
      if ($height > 320) 
      {
          $height = 320;
      }
    }else $height = 320;

  $ret = preg_replace("#(^|[n ]])([w]+?://[w#$%&~/.-;:=,?@+]*)#ise", "'\1<a href="".$imgsrc."" ".$target."><img src="\2" height="".$height.""></img></a>'", $ret);

}

  return($ret);
}

May be better use preg_replace for find clear link to picture without tags, but i dot'n know regular expressions...
Sorry for my bad english.
Last edited by Index on Wed Apr 13, 2011 8:30 am, edited 1 time in total.
Index
New member
 
Posts: 2
Joined: Wed Apr 13, 2011 8:07 am
Top

Postby mfischer » Fri Apr 29, 2011 12:39 am

Okay, index... so where do i paste that? also, with the original script, i keep getting this: error on line 75 (the lin that has }else{ on it. im not good at php, so sorry if im making an obvious mistake.
mfischer
New member
 
Posts: 2
Joined: Thu Apr 28, 2011 4:56 am
Top

Postby Index » Fri Apr 29, 2011 1:46 pm

mfischer wrote:Okay, index... so where do i paste that? also, with the original script, i keep getting this: error on line 75 (the lin that has }else{ on it. im not good at php, so sorry if im making an obvious mistake.

I share full source code of file pfcurlprocessing.php, so you can save (backup) old file and replace it by my one:
http://snipt.org/xqog
Index
New member
 
Posts: 2
Joined: Wed Apr 13, 2011 8:07 am
Top

Postby quutoo » Mon Jun 13, 2011 4:23 am

Index wrote:
mfischer wrote:Okay, index... so where do i paste that? also, with the original script, i keep getting this: error on line 75 (the lin that has }else{ on it. im not good at php, so sorry if im making an obvious mistake.

I share full source code of file pfcurlprocessing.php, so you can save (backup) old file and replace it by my one:
http://snipt.org/xqog

Thank you very much for your sharing.

It works fine.
quutoo
Member
 
Posts: 12
Joined: Sat Jun 11, 2011 1:40 pm
Top

Postby valtimore » Thu Dec 22, 2011 9:59 pm

Link is broken, I need this file please someone help me
valtimore
New member
 
Posts: 1
Joined: Thu Dec 22, 2011 9:55 pm
Top

Postby provotector » Tue Jun 12, 2012 2:43 am

There is a problem with tis improvement.

If the image size is very large, the chat freezes. If you have a troll inside the room, there is a problem with tis.

Hoy can I fix that?

Thanks for all.
http://www.shurchat.com
provotector
Member
 
Posts: 33
Joined: Fri Apr 27, 2012 4:09 am
Top


Post a reply
10 posts • Page 1 of 1

Return to How-to (v1.x)

Who is online

Users browsing this forum: No registered users and 2 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub