-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_image.php
More file actions
62 lines (48 loc) · 1.91 KB
/
write_image.php
File metadata and controls
62 lines (48 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require 'assets/connect.php';
//header('Content-type: image/jpeg');
$img_name = 'img_'.rand().'_'.date('ymd_his');
$ch = curl_init($_REQUEST['img_url']);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);
$fp = fopen('post_images/'.$img_name,'w');
fwrite($fp, $rawdata);
fclose($fp);
// Create Image From Existing File
$jpg_image = imagecreatefromjpeg('post_images/'.$img_name);
$height = 200;
$width = 250;
list($orig_width, $orig_height) = getimagesize('post_images/'.$img_name);
$ratio = $orig_width / $orig_height;
if ($ratio < 1) {
$width = $height * $ratio;
} else {
$height = $width / $ratio;
}
// Allocate A Color For The Text
$white = ImageColorAllocate($jpg_image, 250, 250, 250);
// Set Path to Font File
$font_path = 'assets/helvetica_neue-webfont.ttf';
// Set Text to Be Printed On Image
$text = $_REQUEST['post_msg'];
// Print Text On Image
//imagestring($jpg_image, 865, 229, 290, $text, $white);
imagettftext($jpg_image, $orig_width/strlen($text), 0, 205, $orig_height/2, $white, $font_path, $text);
// Send Image to Browser
imagejpeg($jpg_image, 'post_images/new_'.$img_name);
// START: resizing image
$new_image = imagecreatetruecolor($width, $height);
imagecopyresized($new_image, $jpg_image,
0, 0, 0, 0,
$width, $height,
$orig_width, $orig_height);
imagejpeg($new_image, 'post_images/new_'.$img_name);
// END
mysql_query("INSERT INTO conversation (msg, sent_on, picture) VALUES ('".$text."', '".date('Y-m-d H:i:s')."', 'post_images/new_".$img_name."')");
echo 'post_images/new_'.$img_name;
// Clear Memory
imagedestroy($jpg_image);
?>