Sorry if im posting this in the wrong section.
I had a old expression2 that Maso made, he had a php script on a webserver but it was taken down. I put the php file that was in his thread of the e2 on my webserver.
[CODE]<?php
if(isset($_GET['image'])) {
$img = $_GET['image'];
$info = getimagesize($img);
if($info[2] <= 3) $source = getSource($info[2],$img);
else exit("IMAGE TYPE NOT SUPPORTED");
$width = $info[0];
$height = $info[1];
if($width<$height) {
$source = imagerotate($source,90,0);
$width = imagesx($source);
$height = imagesy($source);
}
if($width*$height > 786432) {
$scale = 1;
while(round($width*$scale)*round($height*$scale) > 786432) {
$scale -= 0.01;
}
$sw = round($width*$scale);
$sh = round($height*$scale);
$temp = imagecreatetruecolor($sw,$sh);
imagecopyresampled($temp,$source,0,0,0,0,$sw,$sh,$width,$height);
$source = $temp;
$width = $sw;
$height = $sh;
}
$s = $width."x".$height.":";
$rep = chr(32);
for($y=0;$y<$height;$y++) {
for($x=0;$x<$width;$x++) {
$rgb = imagecolorat($source,$x,$y);
$r = ($rgb >> 16) & 0xFF;
$r = $r < 32 ? $rep : chr($r);
$g = ($rgb >> 8) & 0xFF;
$g = $g < 32 ? $rep : chr($g);
$b = $rgb & 0xFF;
$b = $b < 32 ? $rep : chr($b);
$s .= ($r.$g.$b);
}
}
echo $s;
}
function getSource($type,$img) {
if($type == 1) $source = imagecreatefromgif($img);
elseif($type == 2) $source = imagecreatefromjpeg($img);
elseif($type == 3) $source = imagecreatefrompng($img);
return $source;
}
?>[/CODE]
when i wire it up, it will only display small images (Like steam avatars) but if i do something bigger i get this [url]http://imgur.com/E30ANf9[/url] (May have to zoom in)
Can someone help me fix the php script?
Here is the e2 if you need it.
[CODE]@name imagewriter
@inputs [DS]:wirelink
@outputs [Percent]
@persist [O]:entity [Ar]:array [Img PHPFile Prefix S]:string [AI Buff Buffer I Length]
#######################
##----- by Maso -----##
#######################
#WARNING: Debugging the "S" variable WILL cause extreme loss in frame rate...
if(first()) {
runOnChat(1)
Prefix = ">"
O = owner()
PHPFile = "dupeprotection.net46.net/image.php" #THANK YOU PAPER CLIP! :D
}
Req = httpCanRequest()
Fin = changed(Req)&Req
if(chatClk(O)) {
Said = lastSaid()
if(Said:index(1) == Prefix) {
hideChat(1)
if(!DS) {print("[WIRELINK A DIGITAL SCREEN FIRST!]")}
else{
Img = Said:sub(2)
if(Img:lower():find("http://")) {
httpRequest(Img)
timer("checkImg",1)
print("[CHECKING IMAGE]")
}
else{print("CHAT EXAMPLE: "+Prefix+"http://www.wiremod.com/forum/customavatars/avatar3378_10.gif")}
}
}
}
if(clk("checkImg")) {
timer("checkImg",1)
if(Req) {
stoptimer("checkImg")
S = httpData()
if(S) {
Status = "FILE EXISTS"
URL = PHPFile + format("?image=%s",Img)
httpRequest(URL)
timer("getImg",1)
}
else{
Status = "FILE DOES NOT EXIST"
}
print("["+Status+"]")
}
}
if(clk("getImg")) {
timer("getImg",1)
if(Req) {
stoptimer("getImg")
S = httpData()
X = S:find("x")
if(X&X <= 6) {
Col = S:find(":")
Dim = S:sub(1,Col-1):explode("x")
W = Dim[1,string]:toNumber()
H = Dim[2,string]:toNumber()
S = S:sub(Col+1)
Length = S:length()
Buffer = round(Length/12)
AI = I = Buff = 0
Ar = array()
DS[1048569]=2 #Color Mode
DS[1048572]=H #Screen Height
DS[1048573]=W #Screen Width
DS[1048574]=1 #Clear Screen
Status = W+"x"+H+" IMAGE LOADING"
timer("writeImg",1)
}
else{Status = S}
print("["+Status+"]")
}
}
if(clk("writeImg")) {
timer("writeImg",1)
while(perf()&I < Length) {
I += 3
AI += 1
Color = (toByte(S,I-2)-16)*65536+(toByte(S,I-1)-16)*256+(toByte(S,I)-16)
Ar[AI,number] = Color
if(AI >= Buffer) {
DS:writeArray(Buff,Ar)
AI = 0
Ar = array()
Buff += Buffer
}
}
if(I == Length) {
S = ""
DS:writeArray(Buff,Ar)
stoptimer("writeImg")
print("[FINISHED WRITING]")
}
Percent = I/Length*100
}[/CODE] NO credit to me
Uhm, yeah. The chat in your imgur pic does show an error, but doesn't show the important bits.
What error does it give specifically? It should be like this:
Call to undefined Function *something* on line *xxx* in *file.php*.
That makes it a bit easier to debug.
It looks like the PHP file is converting the contents of the image into a string, pixel by pixel. Then the E2 script is recreating the image based off of the string-image. Running the php script on localhost seems to give the expected results (image size and a very long string).
Double check that you have GD extensions installed to the server.
[QUOTE=deadeye536;40887529]It looks like the PHP file is converting the contents of the image into a string, pixel by pixel. Then the E2 script is recreating the image based off of the string-image. Running the php script on localhost seems to give the expected results (image size and a very long string).
Double check that you have GD extensions installed to the server.[/QUOTE]
Gd? in not very good with these network things
[QUOTE=Cbhalo;40893716]Gd? in not very good with these network things[/QUOTE]
[URL="http://en.wikipedia.org/wiki/GD_Graphics_Library"]GD Graphics Library[/URL]
If you're hosting with a reputable hosting provider, chances are high that GD is already installed. If you're hosting it on your own machine or a VPS, you may have to install or configure it yourself.
To check if you have GD installed and running on your server, you'll need to create a php info file.
Within this file, search for a dedicated GD section. (most web servers display this under the 'ftp' section, but the location varies)
If no GD section exists, you'll have to compile it. Note that this will require a recompile of PHP, which may cause a short downtime.
To compile GD Library, go to WHM -> Software -> Apache Update. Once you make your way to the Exhaustive Options List, which is step 5 of the process, simply check the box beside 'GD' and continue on.
Once PHP has been compiled, GD will be installed and active. Although there's no guarantee that GD will fix your image problems, it's always good to have an active version of GD installed onto any web server. So, if it's not already on there, put it on as soon as you can.
GD is already installed, otherwise the 4th line would return an undefined function error. You say issue only occurs with large images, my best guess would be that the problem lies within this chunk of code: (assuming the E2 code is fine)
[php]if($width*$height > 786432) {
$scale = 1;
while(round($width*$scale)*round($height*$scale) > 786432) {
$scale -= 0.01;
}
$sw = round($width*$scale);
$sh = round($height*$scale);
$temp = imagecreatetruecolor($sw,$sh);
imagecopyresampled($temp,$source,0,0,0,0,$sw,$sh,$width,$height);
$source = $temp;
$width = $sw;
$height = $sh;
}
[/php]
It looks like the PHP computer file is transforming the material of the picture into a sequence, pixel by pixel. Then the E2 program is re-creating the picture centered off of the string-image
[url=http://www.cariblue.com.au/growing-franchises.html]Franchising a business[/url]
Sorry, you need to Log In to post a reply to this thread.