Re: Copy of image -> smaller
| From: | Rabin Vincent | Date: | Mon, 15 May 2006 11:35:16 +0000 |
| Subject: | Re: Copy of image -> smaller | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-236184@lists.php.net to get a copy of this message | ||
On 5/15/06, Gustav Wiberg <gustav@varupiraten.se> wrote:
[snip]
//What should/could I do here?
//
//Set new width and height
//
$new_width = 100;
$new_height = 200;
$tmp_image=imagecreatefromjpeg($toPath . $mfileAdd);
$width = imagesx($tmp_image);
$height = imagesy($tmp_image);
$new_image = imagecreatetruecolor($new_width,$new_height);
ImageCopyResized($new_image, $tmp_image,0,0,0,0, $new_width,
$new_height, $width, $height);
I can't see anything wrong with this resizing.
//Grab new image
ob_start();
ImageJPEG($new_image);
$image_buffer = ob_get_contents();
ob_end_clean();
ImageDestroy($new_image);
//Create temporary file and write to it
$fp = tmpfile();
fwrite($fp, $image_buffer);
rewind($fp);
Instead of doing this, you may want to use the filename
argument of ImageJPEG to save the image directly to a file.
//Upload new image
$copyTo = 'http://www.ledins.se/test.jpg';
$conn_id = ftp_connect('<domain>');
ftp_login($conn_id,'<username for domain>','<password>');
ftp_fput($conn_id, $copyTo, $fp, FTP_BINARY);
Destination file ($copyTo) is supposed to be a path (eg.
public_html/test.jpg) and not a URL.
Rabin