public static function size($id, $img)
{ try { list($width, $height, $img_type, $attr) = @getimagesize($img);
$imageinfo = array('width' => $width, 'height' => $height, 'type' => image_type_to_extension($img_type, false), 'attr' => $attr); if ($imageinfo) {
$fun = "imagecreatefrom" . $imageinfo['type'];
$image = $fun($img);
$percent = '0.5';
$new_width = $imageinfo['width'] * $percent;
$new_height = $imageinfo['height'] * $percent;
$image_thump = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_thump, $image, 0, 0, 0, 0, $new_width, $new_height, $imageinfo['width'], $imageinfo['height']); imagedestroy($image);
$image = $image_thump;
$func = 'image' . $imageinfo['type'];
$title = str_replace('image', 'img_cory', $img);
$func($image, $title); Db::table('product')->where(array('id' => $id))->update(['image' => $title]);
}
} catch (Exception $e) { echo $id;
}
}