Image Download & View

By Jonesy44 on May 17, 2008

Well, imma be honest, i'm pretty proud of this script. But here's what it does;

For when someone wants to show you an image, but you've already closed the inernet, or your just generally too lazy to flick alt + tab,

  • Hit the Image Viewer button on your mIRC
  • Enter the image URL they sent you
  • Wait for the image to be downloaded
  • And there it is, on your mIRC!

This works using sockets to download the image file, picwins to display it, then the image being scrapped, so it doesn't clogg any memory/cache space.

Hope you enjoy and give positive feedback, rate !
Thanks to Lindrian for his help with the socket :]
~Jonesy

Image

menu * {
  Image Viewer: imgviewer
}
alias imgviewer {
  dialog -m imgviewer imgviewer
}
dialog imgviewer {
  size -1 -1 200 100
  title "Image Viewer Console"
  option dbu
  edit "", 1, 2 2 140 10, autohs
  button "View Image", 2, 144 2 54 10
  edit "", 3, 2 14 196 10, read autohs center
  text "History", 4, 2 30 100 10
  list 5, 2 37 196 70
}
on *:DIALOG:imgviewer:init:*: {
  refresh.histimgs
}
on *:DIALOG:imgviewer:sclick:*: {
  if ($did == 2) {
    getimg $did(1).text
    if (!$read(imghistory.dat, w, $did(1).text)) {
      write imghistory.dat $did(1).text
    }
    refresh.histimgs
  }
  if ($did == 5) {
    did -r imgviewer 3
  }
}
on *:DIALOG:imgviewer:dclick:*: {
  if ($did == 5) {
    write -ds $+ $did(5).seltext imghistory.dat
    write imghistory.dat $did(5).seltext
    did -ra imgviewer 1 $did(5).seltext
    getimg $did(5).seltext
    refresh.histimgs
  }
}
alias refresh.histimgs {
  var %x = 1
  did -r imgviewer 5
  while (%x <= $lines(imghistory.dat)) {
    did -i imgviewer 5 1 $read(imghistory.dat, %x)
    inc %x 1
  }
}
alias getimg {
  dialog $iif($dialog(imgviewer),-v,-m) imgviewer imgviewer
  if (% isin $1-) {
    did -ra imgviewer 3 Please remove any "%" from the URL
    halt
  }
  if ($right($1-,4) == .jpg || $right($1-,4) == .gif || $right($1-,4) == .png) {
    did -r imgviewer 3
    window -paoCzdk0 +tnbL @image.download -1 -1 600 50
    clear @image.download
    drawtext @image.download 14 5 5 Downloading Temporary Image: 0KB
    img.download $1-
  }
  else {
    did -ra imgviewer 3 Unsupported Image format: $right($1-,4)
    halt
  }
}
alias img.download {
  var %r $remove($1,http://),%y $ticks,%1 $gettok(%r,1,47),%o $pos(%r,/),%2 $mid(%r,%o,$calc(1+$pos(%r,/,$count(%r,/))-%o)),%u $remove(%r,%1,%2),%4 $iif($count(%u,.),$gettok(%u,$calc(1+$v1),46)),%3 $remove(%u,%4),%i %3 $+ %4
  sockopen imgdload. $+ %y %1 80
  sockmark imgdload. $+ %y %1 %2 %3 %4
}
on *:sockopen:imgdload.*:{
  if ($sockerr) echo -a Socket error: $sock($sockname).wsmsg
  else {
    tokenize 32 $sock($sockname).mark
    sockwrite $sockname $+(GET $2,$3,$4 $chr(32) HTTP/1.1,$lf,Host: $1,$lf,$lf)
  }
}
on *:sockread:imgdload.*:{
  if (!$sockerr) {
    var %a 1,%v $numtok($sock($sockname).mark,32)
    while %a && %v > 2 {
      sockread %a
      if ($regex(%a,/Content\-Type: .*?\/([^\s;]+)/i)) var %t $iif($regml(1) != plain,$v1)
      if ($regex(%a,/Content\-Length: (\d+)/i)) var %l $regml(1)
    }
    if (%v > 2) sockmark $sockname $gettok($sock($sockname).mark,3,32) $+ %t %l $gettok($sock($sockname).mark,5-,32)
    tokenize 32 $sock($sockname).mark
    while $sock($sockname).rq {
      clear @image.download
      drawtext @image.download 14 5 5 Downloading Temporary Image: $bytes($2).suf
      sockread &b
      bwrite $1 -1 -1 &b
    }
    if ($lof($1) >= $2) {
      clear @image.download
      drawtext @image.download 14 5 5 File Image Download Complete: $bytes($2).suf
      window -paoCzdk0 @image.( $+ $1 $+ ) -1 -1 $calc($pic($1).width + 20) $calc($pic($1).height + 50)
      /drawfill @image.( $+ $1 $+ ) 0 0 1 1
      drawpic @image.( $+ $1 $+ ) 5 5 $1
      .remove $1
      .sockclose $sockname
    }
  }
  else .sockclose $sockname
  unset %dl.dir
}
on *:CLOSE:@image*: {
  if ($window(@image.download)) {
    window -c @image.download
  }
}

Comments

Sign in to comment.
Hrki   -  Feb 21, 2011

Awsome script, it would be nice if i could right click on image url, and if there's an option to show picture using this snippet

 Respond  
^Neptune   -  Oct 15, 2008

Finally. >_>

 Respond  
Jonesy44   -  Oct 15, 2008

Sure.. i'll get round to it soon. restored to XP, back on mirc :D:D

 Respond  
Eugenio   -  Oct 15, 2008

tbh that idea of hawkee's does pwn

 Respond  
Hawkee   -  Jul 31, 2008

Now combine this with a snippet that finds the recently liked images on Hawkee and then you\'ve got something =)

 Respond  
guest598594   -  Jul 31, 2008

Looks nice man. ^^Was about to say what ratsoid said, you should make an on hotlink event so you can right-click an image URL :)

 Respond  
ratsoid   -  Jul 31, 2008

When right clicking a link that ends in jpg/png/gif, you should implement an option that says \"View image\".

 Respond  
Jonesy44   -  May 18, 2008
  • History now functions for already set history, updates list if you use history.
 Respond  
Jonesy44   -  May 18, 2008

Updated, once more.

  • Error in regex should now be sorted. Something screwed up in the copy and paste :-s
  • Dialog alignment
  • Image History
 Respond  
Jonesy44   -  May 18, 2008

LoL, wide dialog !
It\'s nicer, and some URL\'s are a bit longer :-s

 Respond  
EL   -  May 17, 2008

D nice man i like it alot dialog could be thinner tho:P

 Respond  
Jonesy44   -  May 17, 2008

I\'ve decided to take up EL\'s idea of creating a dialog for grabbing the images.
So uuhhh, yeah, try it out, any feedback ;D

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.