How can I resize an image from URL using PHP? -


i'm receiving images urls , save these images new directory, in 3 different sizes. i'm getting urls here, need way resize each image, specific height , width.

i dont want resize uploaded images, images specific url.

my code:

$content = file_get_contents('http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg'); $name = "http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg"; $parts = explode('.', $name); $new_url = rand(0, pow(10, 5)) . '_' . time() . '.' . $parts[count($parts) - 1]; file_put_contents(directory.'/' . $new_url , $content); 

how can that? thanks.

here solution based on imagecopyresampled (gd library) http://php.net/manual/en/function.imagecopyresampled.php

$content = file_get_contents('http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg'); $name = "http://www.joomlaworks.net/images/demos/galleries/abstract/7.jpg"; $parts = explode('.', $name); $new_url = rand(0, pow(10, 5)) . '_' . time() . '.' . $parts[count($parts) - 1]; file_put_contents(directory.'/' . $new_url , $content);  resizeimage($new_url, directory.'/1_' . $new_url, 100, 100); resizeimage($new_url, directory.'/2_' . $new_url, 200, 200); resizeimage($new_url, directory.'/3_' . $new_url, 300, 300);  function resizeimage($source, $dest, $new_width, $new_height) {     list($width, $height) = getimagesize($source);     $image_p = imagecreatetruecolor($new_width, $new_height);     $image = imagecreatefromjpeg($source);     imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);     imagejpeg($image_p, $dest, 100); } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -