Use php to cut the pictures that are uploaded to the database.

51 5
$uploadedfile = $_FILES['uploadfile']['tmp_name'];
$source = ImageCreateFromJPEG($uploadedfile);
list($width,$height) = GetImageSize($uploadedfile);
if ($width> $height) {
 $xoord = ceil(($width-$height)/2);
 $width = $height;
} else {
 $yoord = ceil(($height-$width)/2);
 $height = $width;
$thumb = ImageCreatetruecolor(100,100);//大图

It's the process of image cutting, assuming that I can operate the database directly through $ db-> select | update | insert. I'm going to.

1 Answers

140 2

Although someone is advised that you don't exist in the database, I'm still telling you if you stick to it. First, the fields you want to save are blob format.

//从最后一行开始, 用一个临时文件做中转
$tmp = '/tmp/'. md5(uniqid());
ImageJPEG($thumb, $tmp, 100);
$str = mysql_real_escape_string(file_get_contents($tmp));
$sql = sprintf("INSERT INTO test (`blob_column`) VALUES ('%s')", $str);