StefanRSA Posted August 21, 2013 Share Posted August 21, 2013 Hi, I am getting an image URL from an xml feed. I am trying to copy the image from the URL in the XML Feed, then rename & resize it. Its only giving me a black resized block for each image resize... This is driving me nuts. Please look at my script and tell me where am I going wrong? set_time_limit(-1); $imgurl='http://path/to/img_main.jpg'; $pic=$imgurl; $img = $pic; //////// GET IMAGE NAME $url_arr = explode ('/', $pic); $ct = count($url_arr); $name = $url_arr[$ct-1]; $name_div = explode('.', $name); $ct_dot = count($name_div); $img_type = $name_div[$ct_dot -1]; /////// GET IMAGE NAME END $name= str_replace(' ', '_', $name); $im = imagecreatefromjpeg($img); $width = imagesx($im); $height = imagesy($im); $newwidth = '400'; $newheight = '240'; $thumb = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagejpeg($thumb,'../ad_images/'.$name); //save image as jpg echo '<img src="../ad_images/'.$name.'"> '; $newwidth1 = '130'; $newheight1 = '98'; $thumb1 = imagecreatetruecolor($newwidth1, $newheight1); imagecopyresized($thumb1, $im, 0, 0, 0, 0, $newwidth1, $newheight1, $width, $height); imagejpeg($thumb1,'../ad_images/130/'.$name); //save image as jpg echo '<img src="../ad_images/130/'.$name.'"> '; $newwidth2 = '65'; $newheight2 = '49'; $thumb2 = imagecreatetruecolor($newwidth2, $newheight2); imagecopyresized($thumb2, $im, 0, 0, 0, 0, $newwidth2, $newheight2, $width, $height); imagejpeg($thumb2,'../ad_images/65/'.$name); //save image as jpg echo '<img src="../ad_images/65/'.$name.'"> <br>'; $dbname=$name; imagedestroy($thumb); imagedestroy($thumb1); imagedestroy($thumb2); imagedestroy($im); Link to comment https://forums.phpfreaks.com/topic/281415-image-copy-resize-rename-fromurl-not-working/ Share on other sites More sharing options...
mac_gyver Posted August 21, 2013 Share Posted August 21, 2013 do you have php's error_reporting set to E_ALL and display_errors to ON so that php would report and display all the errors it detects? Link to comment https://forums.phpfreaks.com/topic/281415-image-copy-resize-rename-fromurl-not-working/#findComment-1446105 Share on other sites More sharing options...
StefanRSA Posted August 21, 2013 Author Share Posted August 21, 2013 //$name='newpicfile'; $url=$imgurl; // create the context set_time_limit(-1); $img = file_get_contents($url); //////// GET IMAGE NAME $url_arr = explode ('/', $url); $ct = count($url_arr); $name = $url_arr[$ct-1]; $name_div = explode('.', $name); $ct_dot = count($name_div); $img_type = $name_div[$ct_dot -1]; $name=$adnr.'_'.$inr.'_'.$name; /////// GET IMAGE NAME END $im = imagecreatefromstring($img); $width = imagesx($im); $height = imagesy($im); $newwidth = '400'; $newheight = '240'; $thumb = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagejpeg($thumb,'../ad_images/'.$name); //save image as jpg //echo '<img src="../ad_images/'.$name.'"> '; $newwidth1 = '130'; $newheight1 = '75'; $thumb1 = imagecreatetruecolor($newwidth1, $newheight1); imagecopyresized($thumb1, $im, 0, 0, 0, 0, $newwidth1, $newheight1, $width, $height); imagejpeg($thumb1,'../ad_images/130/'.$name); //save image as jpg //echo '<img src="../ad_images/130/'.$name.'"> '; $newwidth2 = '65'; $newheight2 = '37'; $thumb2 = imagecreatetruecolor($newwidth2, $newheight2); imagecopyresized($thumb2, $im, 0, 0, 0, 0, $newwidth2, $newheight2, $width, $height); imagejpeg($thumb2,'../ad_images/65/'.$name); //save image as jpg echo '<img src="../ad_images/65/'.$name.'"> <br>'; $dbname=$name; $pquery = "INSERT INTO *****"; mysql_query($pquery); imagedestroy($thumb); imagedestroy($thumb1); imagedestroy($thumb2); imagedestroy($im); Am sure this will help somewhere, someone else... ;-) Thanks for the reply mac Link to comment https://forums.phpfreaks.com/topic/281415-image-copy-resize-rename-fromurl-not-working/#findComment-1446106 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.