...

View Full Version : supplied argument is not a valid Image resource



Remix919
04-27-2011, 05:24 AM
I know there have probably been lots of posts about this issue, but I have read through over 30+ posts already and have not found my answer. So...here's my problem, I'm running a script to get feeds and put them into my database, and for some weird reason, one of my scripts work fine, but when I try to use the script for another feed, I get the not valid Image resource error and the original jpg that it tries to copy over from the other server is a blank pic and the 2 images I try to resize are black. I'm not sure if there is such a thing as server image protection or something, but I am completely out of ideas. Please help! Here's the code:


foreach(array_slice($imgdata, 0) as $key=>$value) {
$url = $value;
$fname = basename("$url");
copy ("$url","/home/autolib/public_html/files/listing_orig_$fname");
$imagephoto = new SimpleImage();
$imagephoto->load($url);
$imagephoto->resize(550,370);
$imagephoto->save("/home/autolib/public_html/files/listing_photo_$fname");
$imagephoto->resize(106,80);
$imagephoto->save("/home/autolib/public_html/files/listing_thumbnail_$fname");
mysql_query("INSERT INTO fl_listing_photos (ID, Listing_ID, Position, Photo, Thumbnail, Original) VALUES ('','$newlisting[ID]','','listing_photo_$fname','listing_thumbnail_$fname','listing_orig_$fname')");
}

And here's the code from the function file:


<?php

class SimpleImage {

var $image;
var $image_type;

function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}
?>

mlseim
04-27-2011, 05:29 AM
Can you give us a link to both feeds, so we can see what the difference might be?

Tell us which one works and which one does not.


.

Remix919
04-27-2011, 05:37 AM
Can you give us a link to both feeds, so we can see what the difference might be?

Tell us which one works and which one does not.


.

Here is the working feed:


"id","listing_type","username","active","keywords","pictures","ZipCode","Year","Vin","Mileage","Video","Price","SellerComments","Address","City","State","YouTubeVideoID","BodyStyle","CustomExteriorColor","ExteriorColor","CustomInteriorColor","InteriorColor","Doors","Engine","Transmission","FuelType","DriveType","DriverAirBag","PassengerAirBag","SideAirBag","AntiLockBrakes","AirConditioning","PowerSteering","CruiseControl","TiltWheel","LeatherSeats","PowerSeats","ChildSeat","PowerWindows","RearWindowDefroster","TintedGlass","AmFmRadio","AmFmStereoTape","CompactDiscPlayer","CompactDiscChanger","AlloyWheels","PowerDoorLocks","PowerMirrors","SunroofMoonroof","Sold","MakeModel[1]","MakeModel[2]","dealershipName","email","phone_number","contact","icon"
"811415","Car","jhcats","1","1970 AMC AMX Go Pack Shadow Mask","http://photos.ecarlist.com/HW/YW/SL/ag/CN/7U/mU/sa/ko/ER/eA_640.jpg;http://photos.ecarlist.com/EL/9m/6N/25/gk/Jo/iD/MN/1C/Zo/fw_640.jpg;http://photos.ecarlist.com/28/G3/XC/L6/oS/EE/Ao/tM/T1/ap/hA_640.jpg;http://photos.ecarlist.com/pw/2W/c5/kY/W0/eL/8T/Xm/35/dJ/2Q_640.jpg;http://photos.ecarlist.com/JY/dx/df/BH/Yk/We/41/py/b3/2w/fg_640.jpg;http://photos.ecarlist.com/PW/hG/aB/sY/aJ/fI/Uj/U7/uT/ix/hQ_640.jpg;http://photos.ecarlist.com/dF/dN/9M/gU/Kw/2Z/FZ/C4/G2/UX/CQ_640.jpg;http://photos.ecarlist.com/Ti/M1/Fd/13/RL/CO/PN/1b/S3/cc/WQ_640.jpg;http://photos.ecarlist.com/nd/RL/LK/U4/BQ/k7/WU/Iz/Mk/yV/3g_640.jpg;http://photos.ecarlist.com/TP/bK/0T/UY/HC/f2/hy/CY/G8/ru/GA_640.jpg;http://photos.ecarlist.com/FA/Q3/Ro/2a/qD/3I/Fj/SY/Nk/tR/uw_640.jpg;http://photos.ecarlist.com/4r/7b/pf/Qi/yV/nX/xN/1Z/rZ/KQ/Aw_640.jpg;http://photos.ecarlist.com/IN/cQ/4J/tR/Og/G4/vp/Sg/nc/hL/xw_640.jpg;http://photos.ecarlist.com/Ze/AR/ef/El/Mx/I1/Es/2V/Os/h9/9g_640.jpg;http://photos.ecarlist.com/Ts/Yb/Sh/mZ/FH/0M/n3/uz/24/g0/Ig_640.jpg;http://photos.ecarlist.com/I2/ig/ZL/oH/iN/Tx/KZ/BM/xd/ff/tQ_640.jpg;http://photos.ecarlist.com/1Z/7k/ZJ/3Q/3I/ky/bs/qw/Vl/fH/9Q_640.jpg;http://photos.ecarlist.com/1i/kU/gF/U2/5n/6b/w2/GF/0c/o1/Lw_640.jpg;http://photos.ecarlist.com/D3/pv/kW/D1/qe/KZ/2M/0Y/mf/GC/Mw_640.jpg;http://photos.ecarlist.com/55/gd/N4/nj/Dc/L6/rR/mQ/zs/K2/WQ_640.jpg;http://photos.ecarlist.com/Zr/S8/6p/8w/PH/O9/cN/Zw/86/sG/7w_640.jpg;http://photos.ecarlist.com/FV/Qa/1z/uf/aq/FD/Wd/eW/DR/9F/sQ_640.jpg;http://photos.ecarlist.com/KN/nN/RU/eh/2K/RY/n1/eK/Iu/FS/Dg_640.jpg;http://photos.ecarlist.com/kJ/ez/V6/q9/Qn/Mk/p6/4s/4r/fL/sA_640.jpg;http://photos.ecarlist.com/zW/Ku/Eo/mx/jX/wb/Tt/1T/NK/XZ/cw_640.jpg;http://photos.ecarlist.com/Or/yh/o3/I5/9f/tF/Ko/Rb/iI/vm/uw_640.jpg;http://photos.ecarlist.com/Bi/1y/Hi/cJ/5t/Eg/xm/8X/jN/ic/rw_640.jpg;http://photos.ecarlist.com/ap/Qk/OM/vC/kq/Yp/4X/73/dK/tF/sQ_640.jpg;http://photos.ecarlist.com/cC/zs/TA/XV/m0/8t/ip/SK/8o/I2/3w_640.jpg;http://photos.ecarlist.com/Ue/yo/7A/uH/J4/EL/YD/i8/ur/eQ/3g_640.jpg;http://photos.ecarlist.com/eg/Md/vt/6g/qP/7o/Va/1e/pS/R6/0Q_640.jpg;http://photos.ecarlist.com/QD/FE/C1/p4/Ei/pd/SO/cO/T8/u6/UA_640.jpg;http://photos.ecarlist.com/st/0R/1M/vF/6y/W0/7a/XX/T2/B4/MQ_640.jpg;http://photos.ecarlist.com/bI/HK/P2/FX/q0/tV/y0/lu/mK/dQ/iA_640.jpg;http://photos.ecarlist.com/KE/l1/mG/Ld/D2/YF/zt/Qp/8T/0G/CA_640.jpg;http://photos.ecarlist.com/0K/wF/ND/0R/ld/o8/mc/xT/9V/9l/gg_640.jpg;http://photos.ecarlist.com/pt/wC/pF/pU/UY/AB/sc/xW/zZ/qv/Hw_640.jpg;http://photos.ecarlist.com/nz/1L/CD/rD/S8/BA/BF/hZ/QI/oc/UQ_640.jpg;http://photos.ecarlist.com/bl/pW/5c/hk/aq/9T/8B/RY/YT/uH/Jw_640.jpg;http://photos.ecarlist.com/Jc/E0/UZ/hz/2s/DD/WG/UT/Wk/cO/Vg_640.jpg;http://photos.ecarlist.com/7s/ol/lE/lG/0x/pB/uS/uk/zi/jG/fg_640.jpg;http://photos.ecarlist.com/F1/uH/1K/qe/HQ/tw/un/nL/0N/Rc/oQ_640.jpg;http://photos.ecarlist.com/yv/rh/1G/p2/fN/zv/o2/gr/r1/88/tw_640.jpg;http://photos.ecarlist.com/8C/bJ/OF/sx/FX/pF/u0/l7/gl/DW/HA_640.jpg;http://photos.ecarlist.com/w8/2j/Zk/7r/b0/qR/cy/0D/i1/YF/fg_640.jpg;http://photos.ecarlist.com/Eu/Rq/Tn/Q1/ra/E5/l9/Iv/1g/fK/Xw_640.jpg;http://photos.ecarlist.com/PH/1f/22/tO/2G/Ca/pV/ni/06/g8/pw_640.jpg;http://photos.ecarlist.com/Gr/2M/KL/rn/vb/JB/wc/xy/mF/E8/Hw_640.jpg;http://photos.ecarlist.com/jM/Nj/lR/H4/81/er/4h/e3/6H/sf/xA_640.jpg;http://photos.ecarlist.com/je/eC/38/AL/kp/K1/kJ/za/Bt/fz/Xw_640.jpg;http://photos.ecarlist.com/52/7x/T9/cz/cp/kN/Ur/rE/GV/2t/qg_640.jpg;http://photos.ecarlist.com/lR/ET/D9/1M/k4/XJ/0G/lR/4F/n2/wA_640.jpg;http://photos.ecarlist.com/R1/2n/VD/iC/al/V0/gE/KI/mF/V3/ng_640.jpg;http://photos.ecarlist.com/9F/5j/qd/O3/Tf/Ls/Ij/f2/0r/EA/Ug_640.jpg;http://photos.ecarlist.com/wb/at/SN/n9/dS/zu/Hk/Va/jf/9v/Dg_640.jpg;http://photos.ecarlist.com/sR/0h/av/SF/Fl/BQ/8s/Uw/mF/Ah/ow_640.jpg;http://photos.ecarlist.com/fu/M9/ff/Ce/1z/y1/kQ/0H/h9/OF/6A_640.jpg;http://photos.ecarlist.com/vy/kV/Kx/Ux/AY/tO/Uz/5g/Yy/0Z/1w_640.jpg;http://photos.ecarlist.com/KN/2G/OT/iO/ap/an/Fe/cv/b1/u2/Cw_640.jpg;http://photos.ecarlist.com/Gn/Jv/dr/2j/DR/PU/mN/7P/sB/YB/8g_640.jpg;http://photos.ecarlist.com/r3/Rx/9G/2j/87/kU/oc/6R/1D/Kb/Dw_640.jpg;http://photos.ecarlist.com/ky/SQ/2O/fU/Ed/MJ/Jk/qQ/Gl/UC/3g_640.jpg;http://photos.ecarlist.com/Dt/Na/3F/z2/qo/43/eN/HP/1a/BR/ew_640.jpg;http://photos.ecarlist.com/gB/qj/Z1/AU/VG/Fp/2q/Eb/Jo/tp/GA_640.jpg;http://photos.ecarlist.com/oP/kc/zS/Xm/hM/kJ/SX/5e/k7/J4/NA_640.jpg;http://photos.ecarlist.com/Sb/NX/Fk/qC/Ek/2y/jp/4j/qQ/4G/Ng_640.jpg;http://photos.ecarlist.com/w8/go/Kh/aB/CM/Rc/A8/2d/xZ/39/mw_640.jpg;http://photos.ecarlist.com/yG/Te/mu/Cu/rn/22/DB/x1/91/dZ/1g_640.jpg;http://photos.ecarlist.com/AH/iC/Y9/Qt/DF/Hw/qF/w5/JT/BL/kw_640.jpg;http://photos.ecarlist.com/1k/mO/2E/a1/gn/LU/0p/QX/fK/E1/oA_640.jpg;http://photos.ecarlist.com/n3/S6/AI/8S/xm/MB/CR/ca/fh/jB/7Q_640.jpg;http://photos.ecarlist.com/Ly/J1/rb/DZ/xu/MZ/Es/6i/K5/NK/6A_640.jpg;http://photos.ecarlist.com/Oy/I9/QP/BS/WW/O5/Oh/5I/ho/63/Eg_640.jpg;http://photos.ecarlist.com/Sr/D0/q2/lH/0E/wJ/do/J2/WS/3n/Mg_640.jpg;http://photos.ecarlist.com/wq/Mj/nj/0j/sY/Vm/qa/Gb/5w/qy/Hg_640.jpg;http://photos.ecarlist.com/M0/S6/Cp/Xo/1o/o2/jD/T2/qg/N0/nA_640.jpg;http://photos.ecarlist.com/w4/x1/Dl/lp/1G/kP/iW/pc/4O/Lm/kA_640.jpg;http://photos.ecarlist.com/82/84/Na/aa/sG/Js/Le/UT/ET/FE/Lw_640.jpg;http://photos.ecarlist.com/LJ/HE/KF/NI/yM/Rm/EP/VX/6I/Kj/6g_640.jpg;http://photos.ecarlist.com/oJ/mU/WR/mn/y8/5K/K1/wp/IF/LN/bA_640.jpg;http://photos.ecarlist.com/Sz/ni/yE/Wy/zC/6p/Ni/S1/SK/Jo/CQ_640.jpg;http://photos.ecarlist.com/3O/6P/jP/Bq/r2/qF/p2/iE/kx/r3/fw_640.jpg;http://photos.ecarlist.com/DR/LA/S5/QX/XW/4s/UE/xx/LC/2g/QQ_640.jpg","98204","1970","A0M397X302686","66557","","29888","1970 AMX Original Shadow Mask car finished in gloss black with FACTORY matte Shadow Mask over black leather interior. Car was born Mosport Green and received a recent re-spray, keeping the factory original Shadow Mask matte black finish, completed in new modern paint materials. Less then 72 of these cars ever produced in 1970 with this mask finish. The Shadow Mask feature is confirmed via the 8 in the door trim tag as this option. This car has traveled just over 66,000 original miles. it has an aftermarket carburetor on it. ***Original carb is included with the sale*** Car has had a refreshing, including new paint re-spray that still today looks and shows as new. Front and rear bumper just completed fresh full re-chrome and look as if new. Power steering, Power Brakes..that stop on a dime. Car is equipped with 15 Crager wheels and newer tires. Car is also equipped with the optional Rim Blow steering wheel as well as the 140MPH speedo gauge. Car has a slight exhaust leak on passenger side elbow joint. In the trunk still remains the original space saver tire as well as fill up air canister. Body is laser straight. Interior is in very very good condition. Car comes with period date correct owners manual. Service records dating back to the 70's included as well. If you are looking for a ORIGINAL 390 Go Pack car...one you can drive and enjoy..your search has ended. As these cars grab more awareness, they are surely likely to climb in value. Call us today for more details on this beautiful, original AMX 390 Go Pack Shadow Mask! Cats Exotics offers a wide variety of Lease and Purchase options! Call for more details! *If payment example is displayed then payment is calculated to reflect a 20% cash/trade equity down payment for a maximum term of 144 months with an APR of 7.99%. Rates and terms are subject to change and loans are subject to individual credit approval. Not all applicants will qualify. All taxes and state fees will be an additional cost. OAC means On Approved Credit. The payment provided by this calculation is for illustrative purposes only and should not be considered an offer to extend credit or an offer of sale. Credit application and approval required. Actual payment and interest rate may vary with each individual situation. Be sure to consult a financial professional prior to relying on the information outlined above. These calculations are intended for illustrative purposes only and accuracy is not guaranteed. Vehicle listings and information are subject to change without notice. Vehicles are also subject to prior sale without notice. This information is intended to be accurate but is not guaranteed. Please verify all information with Cats Exotics sales staff. ","1730 Gibson Rd","Everett","Washington","","Coupe","Black with matte black Shadow Ma","Black","Black","Black","2","390 Go Pack V8","Manual","Gasoline","Rear Wheel","","","","","","","","","","","","","","","","","","","","","","","0","AMC","AMX","CatsExotics","sales@catsexotics.com","425-353-2287","Roy L Cats",""


And here is the one that doesn't work:


"DEALERSHIPNAME","VIN","STOCKNUMBER","NEW_USED","YEAR","MAKE","MODEL","TRIM","BODY","TRANSMISSION","MILES","ENGINE","EXTCOLOR","INTCOLOR","SELLINGPRICE","DESCRIPTION","OPTIONS","PHOTOURLS"
"South Beach Classics","","00NE036","used","1964","Ford","Galaxie XL Convertible","","","","0","8 Cylinder Engine","BLUE","BLUE","24500","No Warranty available on cars of classic vintage for due to their vintage nature one can not guarantee perfect operation and condition.","Pre-Owned, Clear Title","http://sobeclassics.com/galleria_images/1/1_main_l.jpg,http://sobeclassics.com/galleria_images/1/1_p2_l.jpg,http://sobeclassics.com/galleria_images/1/1_p3_l.jpg,http://sobeclassics.com/galleria_images/1/1_p4_l.jpg,http://sobeclassics.com/galleria_images/1/1_p5_l.jpg,http://sobeclassics.com/galleria_images/1/1_p6_l.jpg,http://sobeclassics.com/galleria_images/1/1_p7_l.jpg,http://sobeclassics.com/galleria_images/1/1_p8_l.jpg,http://sobeclassics.com/galleria_images/1/1_p9_l.jpg,http://sobeclassics.com/galleria_images/1/1_p10_l.jpg,http://sobeclassics.com/galleria_images/1/1_p11_l.jpg,http://sobeclassics.com/galleria_images/1/1_p12_l.jpg,http://sobeclassics.com/galleria_images/1/1_p13_l.jpg,http://sobeclassics.com/galleria_images/1/1_p14_l.jpg,http://sobeclassics.com/galleria_images/1/1_p15_l.jpg,http://sobeclassics.com/galleria_images/1/1_p16_l.jpg,http://sobeclassics.com/galleria_images/1/1_p17_l.jpg,http://sobeclassics.com/galleria_images/1/1_p18_l.jpg,http://sobeclassics.com/galleria_images/1/1_p19_l.jpg,http://sobeclassics.com/galleria_images/1/1_p20_l.jpg,http://sobeclassics.com/galleria_images/1/1_p21_l.jpg,http://sobeclassics.com/galleria_images/1/1_p22_l.jpg,http://sobeclassics.com/galleria_images/1/1_p23_l.jpg,http://sobeclassics.com/galleria_images/1/1_p24_l.jpg"


Here is the exact error I'm getting:


Warning: imagesx(): supplied argument is not a valid Image resource in /home/autolib/public_html/import/resize.php on line 41

Warning: imagesy(): supplied argument is not a valid Image resource in /home/autolib/public_html/import/resize.php on line 44

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/autolib/public_html/import/resize.php on line 63

But like I said, with the first feed, no errors at all, works perfectly fine, I'm so confused... O.o~

Remix919
04-27-2011, 04:20 PM
bump.

mlseim
04-27-2011, 07:34 PM
In the first feed, the photo file names are separated by semi-colons ;

In the second feed, the photo file names are separated by commas ,



Somewhere before your "foreach" loop, you must have parsed the feed?
Maybe you can do a string replace to change those commas to semi-colons ...

$string=str_replace("jpg,","jpg;",$string);



.

Remix919
04-27-2011, 09:23 PM
In the first feed, the photo file names are separated by semi-colons ;

In the second feed, the photo file names are separated by commas ,



Somewhere before your "foreach" loop, you must have parsed the feed?
Maybe you can do a string replace to change those commas to semi-colons ...

$string=str_replace("jpg,","jpg;",$string);



.

O, ok, I was getting the data like this:


$imgdata = explode(",", $data[17]);


But I guess I can't put the comma in between the two quotes or it won't read right. I'll change it to a semi colon and do the string replace in the feed and see how that works :)

I changed it to the following but it still has the same error :(


$imgurls = str_replace("jpg,","jpg;",$data[17]);
$imgdata = explode(";", $imgurls);

foreach(array_slice($imgdata, 0) as $key=>$value) {
$url = $value;
$fname = basename("$url");
echo "$url - $fname<br><br>";
copy ("$url","/home/autolib/public_html/files/listing_orig_$fname");
$imagephoto = new SimpleImage();
$imagephoto->load($url);
$imagephoto->resize(550,370);
$imagephoto->save("/home/autolib/public_html/files/listing_photo_$fname");
$imagephoto->resize(106,80);
$imagephoto->save("/home/autolib/public_html/files/listing_thumbnail_$fname");
mysql_query("INSERT INTO fl_listing_photos (ID, Listing_ID, Position, Photo, Thumbnail, Original) VALUES ('','$newlisting[ID]','','listing_photo_$fname','listing_thumbnail_$fname','listing_orig_$fname')");
}

mlseim
04-27-2011, 09:28 PM
this might work ....

$data[17]=str_replace("jpg,","jpg;",$data[17]);
$imgdata = explode(";", $data[17]);

Remix919
04-27-2011, 09:37 PM
this might work ....

$data[17]=str_replace("jpg,","jpg;",$data[17]);
$imgdata = explode(";", $data[17]);

Nope, still same problem :\ I can give you the full script and test URL if you want to take a look. Still the same error message :( It's just really odd because this script works fine with the first feed...can't figure out what's wrong.

mlseim
04-28-2011, 03:40 AM
PM me with the full script ... and test URL.
... unless you feel it's OK to post here.


.

Remix919
04-28-2011, 04:46 AM
PM me with the full script ... and test URL.
... unless you feel it's OK to post here.


.

PM Sent, thanks a lot :D

Remix919
04-29-2011, 01:30 AM
bump.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum