php - Image Resize and Upload -
i trying upload images using import.csv file. images need resized before uploading. using code uploading returning black image of given size.
<?php error_reporting(e_all); include('config.php'); include('inc/header.php'); define('csv_path', ''); $csv_file = csv_path . "importimage.csv"; // name of csv file $csvfile = fopen($csv_file, 'r'); $thedata = fgets($csvfile); $i = 0; while (!feof($csvfile)) { $csv_data[] = fgets($csvfile, 1024); $csv_array = explode(",", $csv_data[$i]); $insert_csv = array(); $url = $insert_csv['url'] = $csv_array[0]; $image = $insert_csv['image'] = $csv_array[1]; $raw = file_get_contents($url . $image); /*resize using gd*/ /* * php gd * resize image using gd library */ // file , new size //the original image has 800x600 $filename = $raw; //the resize percent of original size $percent = 0.5; // content type header('content-type: image/jpeg'); // new sizes list($width, $height) = getimagesize($filename); $newwidth = 200; $newheight = 200; // load $thumb = imagecreate($newwidth, $newheight); $source = imagecreate($filename); // resize $imgnew = imagecopyresampled($thumb, $source, 0, 0, 0, 0, newwidth, $newheight, $width, $height); imagejpeg($thumb, 'mypath' . time() . '.jpg'); // save resized image //output , free memory imagedestroy($thumb); $i++; } fclose($csvfile); echo "file data imported database!!"; mysql_close($connect); ?>
the following script allow resize images using php , gd library.
https://github.com/nomisoft/white-hat-classes/tree/master/simple-image
Comments
Post a Comment