function get_photo_size($savepath, $width = 200) { $info = getImageInfo($savepath); list($old_width, $old_height) = $info; $rate = $old_width / $old_height; $height = $width / $rate; return array($width, $height); }
function getColorGrid(&$image, $pixelType = PX_ARRAY) { $imageInfo = getImageInfo($image); $colorGrid = array(); for ($y = 0; $y < $imageInfo['height']; $y++) { $colorGrid[$y] = array(); for ($x = 0; $x < $imageInfo['width']; $x++) { $colorGrid[$y][$x] = $pixelType === PX_ARRAY ? imagecolorsforindex($image, imagecolorat($image, $x, $y)) : colorToHex(imagecolorsforindex($image, imagecolorat($image, $x, $y)), $pixelType); } } return $colorGrid; }
public function getImageInfo() { $data = getImageInfo('2012/1110/18/509e2b90e7a89.jpeg'); dump($data); }
/** * 添加频道与分享的关联信息 * @param integer $sourceId 分享ID * @param array $channelIds 频道分类ID数组 * @param boolean $isAdmin 是否需要审核,默认为true * @return boolean 是否添加成功 */ public function setChannel($feedId, $channelIds, $isAdmin = true) { // 格式化数据 !is_array($channelIds) && ($channelIds = explode(',', $channelIds)); // 检验数据 if (empty($feedId)) { return false; } // 删除分享的全部关联 $map['feed_id'] = $feedId; $res = $this->where($map)->delete(); // 删除成功 if ($res !== false) { $data['feed_id'] = $feedId; // 获取图片的高度与宽度 $feedInfo = model('Feed')->get($feedId); if ($feedInfo['type'] == 'postimage') { $feedData = unserialize($feedInfo['feed_data']); $imageAttachId = is_array($feedData['attach_id']) ? $feedData['attach_id'][0] : $feedData['attach_id']; $attach = model('Attach')->getAttachById($imageAttachId); $imageInfo = getImageInfo($attach['save_path'] . $attach['save_name']); if ($imageInfo !== false) { $data['width'] = ceil($imageInfo[0]); $data['height'] = ceil($imageInfo[1]); } } else { if ($feedInfo['type'] == 'postvideo') { $feedData = unserialize($feedInfo['feed_data']); $imageInfo = getimagesize($feedData['flashimg']); if ($imageInfo !== false) { $data['width'] = $imageInfo[0]; $data['height'] = $imageInfo[1]; } } } // 用户UID $data['uid'] = $feedInfo['uid']; // 获取后台配置数据 $channelConf = model('Xdata')->get('channel_Admin:index'); $isAudit = $channelConf['is_audit'] == 1 ? false : true; foreach ($channelIds as $channelId) { $data['channel_category_id'] = $channelId; if ($isAdmin) { $data['status'] = 1; } else { if ($isAudit) { $data['status'] = 0; } else { $data['status'] = 1; } } $this->add($data); } return true; } return false; }
private function receiveImage($object) { require_once 'faceplusplus.php'; $content = getImageInfo((string) $object->PicUrl); $result = $this->transmitText($object, $content); return $result; }
private function saveInfo($upload_info, $options) { $data = array('table' => t($data['table']), 'row_id' => t($data['row_id']), 'app_name' => t($data['app_name']), 'attach_type' => t($options['attach_type']), 'uid' => (int) $data['uid'] ? $data['uid'] : $GLOBALS['ts']['mid'], 'ctime' => time(), 'private' => $data['private'] > 0 ? 1 : 0, 'is_del' => 0, 'from' => isset($data['from']) ? intval($data['from']) : getVisitorClient()); if ($options['save_to_db']) { foreach ($upload_info as $u) { $name = t($u['name']); $data['name'] = $name ? $name : $u['savename']; $data['type'] = $u['type']; $data['size'] = $u['size']; $data['extension'] = strtolower($u['extension']); $data['hash'] = $u['hash']; $data['save_path'] = $options['custom_path']; $data['save_name'] = $u['savename']; if (in_array($data['extension'], array('jpg', 'gif', 'png', 'jpeg', 'bmp')) && !in_array($options['attach_type'], array('feed_file', 'weiba_attach'))) { list($width, $height) = getImageInfo($data['save_path'] . $data['save_name']); $data['width'] = $width; $data['height'] = $height; } else { $data['width'] = 0; $data['height'] = 0; } $aid = $this->add($data); $data['attach_id'] = intval($aid); $data['key'] = $u['key']; $data['size'] = byte_format($data['size']); $infos[] = $data; } } else { foreach ($upload_info as $u) { $name = t($u['name']); $data['name'] = $name ? $name : $u['savename']; $data['type'] = $u['type']; $data['size'] = byte_format($u['size']); $data['extension'] = strtolower($u['extension']); $data['hash'] = $u['hash']; $data['save_path'] = $options['custom_path']; $data['save_name'] = $u['savename']; //$data['save_domain'] = C('ATTACH_SAVE_DOMAIN'); //如果做分布式存储,需要写方法来分配附件的服务器domain $data['key'] = $u['key']; $infos[] = $data; } } return $infos; }
function resize($ori) { if (preg_match('/^http:\\/\\/[a-zA-Z0-9]+/', $ori)) { return $ori; } $info = getImageInfo(AVATARS_PATH . $ori); if ($info) { //上传图片后切割的最大宽度和高度 $dst_width = 100; $dst_height = 100; $scrimg = AVATARS_PATH . $ori; if ($info['type'] == 'jpg' || $info['type'] == 'jpeg') { $im = imagecreatefromjpeg($scrimg); } if ($info['type'] == 'gif') { $im = imagecreatefromgif($scrimg); } if ($info['type'] == 'png') { $im = imagecreatefrompng($scrimg); } if ($info['type'] == 'bmp') { $im = imagecreatefromwbmp($scrimg); } if ($info['width'] <= $dst_width && $info['height'] <= $dst_height) { return; } else { if ($info['width'] > $info['height']) { $height = intval($info['height']); $width = $height; $x = ($info['width'] - $width) / 2; $y = 0; } else { $width = intval($info['width']); $height = $width; $x = 0; $y = ($info['height'] - $height) / 2; } } $newimg = imagecreatetruecolor($width, $height); imagecopy($newimg, $im, 0, 0, $x, $y, $info['width'], $info['height']); $scale = $dst_width / $width; $target = imagecreatetruecolor($dst_width, $dst_height); $final_w = intval($width * $scale); $final_h = intval($height * $scale); imagecopyresampled($target, $newimg, 0, 0, 0, 0, $final_w, $final_h, $width, $height); imagejpeg($target, AVATARS_PATH . $ori); imagedestroy($im); imagedestroy($newimg); imagedestroy($target); } return; }
public function weibo_photo() { // 获取分享配图信息 $uid = $this->data['uid'] ? intval($this->data['uid']) : $this->mid; $count = $this->count > 0 ? intval($this->count) : 10; $page = $this->page > 0 ? intval($this->page) : 1; $feedImages = $this->getUserAttachData($uid, $count, $page); foreach ($feedImages as &$v) { $v['imageinfo'] = getImageInfo($v['savepath']); $v['savepath'] = getImageUrl($v['savepath']); } return $feedImages; }
<?php /** * Creates negative sprites from normal sprites. * * @author Stefan Hahn * @copyright 2011-2012 Stefan Hahn * @license Simplified BSD License License <http://projects.swallow-all-lies.com/licenses/simplified-bsd-license.txt> */ require_once './lib.php'; $sprites = glob('./sprites/*.png'); if (!is_dir('./negative')) { mkdir('./negative'); } foreach ($sprites as $sprite) { $image = imagecreatefrompng($sprite); $imageInfo = getImageInfo($image); $newImage = imagecreatetruecolor($imageInfo['width'], $imageInfo['height']); $colors = array(); echo 'Turning sprite ' . basename($sprite, '.png') . ' to negative' . "\n"; imagealphablending($newImage, false); imagesavealpha($newImage, true); imagefill($newImage, 0, 0, imagecolorallocatealpha($newImage, 0xff, 0xff, 0xff, 0x7f)); for ($y = 0; $y < $imageInfo['height']; $y++) { for ($x = 0; $x < $imageInfo['width']; $x++) { $color = imagecolorsforindex($image, imagecolorat($image, $x, $y)); if ($color['alpha'] < 0x7f) { $hex = ownDecHex($color['red']) . ownDecHex($color['green']) . ownDecHex($color['blue']); if (!isset($colors[$hex])) { $colors[$hex] = imagecolorallocatealpha($newImage, 0xff - $color['red'], 0xff - $color['green'], 0xff - $color['blue'], 0x0); } imagesetpixel($newImage, $x, $y, $colors[$hex]);
function handleOne($picName) { global $options; global $inputInfo; global $picArr; $imgInfo = getImageInfo($picName); $ratio = $options["ratio"]; $w = $imgInfo["width"] / $ratio; $h = $imgInfo["height"] / $ratio; // 按宽度分组 $key = null; if ($options["group"]) { $key = $w; } else { $key = 0; if ($maxWidth < $w) { $maxWidth = $w; } } if (!array_key_exists($key, $inputInfo)) { $inputInfo[$key] = ["x" => 0, "y" => 0, "pics" => []]; } $e =& $inputInfo[$key]; $pic = ["file" => $picName, "width" => $w, "height" => $h, "x" => $e["x"], "y" => $e["y"]]; $e["pics"][] = $pic; $picArr[] = $pic; $e["x"] -= $w; $e["y"] -= $h; unset($e); }
if ($width <= 90 && $height <= 90) { print "*small* "; } list($thumbWidth, $thumbHeight, $ignored) = preg_split('/\\|/', getImageInfo($thumbName)); $book->thumbWidth = $thumbWidth; $book->thumbHeight = $thumbHeight; $book->save(); } else { if ($imgType == IMG_NOT_JPEG) { print " Not an image "; } else { print " Corrupted image "; } } } elseif ($alreadyResized) { list($thumbWidth, $thumbHeight, $ignored) = preg_split('/\\|/', getImageInfo($thumbName)); $book->thumbWidth = $thumbWidth; $book->thumbHeight = $thumbHeight; $book->save(); print " Already processed, skipping "; } else { print " Cannot fetch image! "; } print "\n"; } function getImageInfo($fileName) { $output = OS::executeAndReturnOutput("identify -format \"%w|%h|%b\" \"{$fileName}\""); assert(count($output) == 1); return $output[0]; }
function scaleScale2x(&$image, &$newImage) { $imageInfo = getImageInfo($image); $imageColorGrid = getColorGrid($image, PX_ARGB); $colors = array(); for ($y = 0; $y < $imageInfo['height']; $y++) { for ($x = 0; $x < $imageInfo['width']; $x++) { $scaledPixel = array($imageColorGrid[$y][$x], $imageColorGrid[$y][$x], $imageColorGrid[$y][$x], $imageColorGrid[$y][$x]); $a = $imageColorGrid[$y === 0 ? $y : $y - 1][$x]; $b = $imageColorGrid[$y][$x === 0 ? $x : $x - 1]; $c = $imageColorGrid[$y][$x === $imageInfo['width'] - 1 ? $x : $x + 1]; $d = $imageColorGrid[$y === $imageInfo['height'] - 1 ? $y : $y + 1][$x]; if ($a !== $d && $b !== $c) { $scaledPixel[0] = $a === $b ? $b : $scaledPixel[0]; $scaledPixel[1] = $a === $c ? $c : $scaledPixel[1]; $scaledPixel[2] = $b === $d ? $b : $scaledPixel[2]; $scaledPixel[3] = $c === $d ? $c : $scaledPixel[3]; } if (!isset($colors[$scaledPixel[0]])) { $colors[$scaledPixel[0]] = imagecolorallocatealpha($newImage, ($scaledPixel[0] & 0xff0000) >> 16, ($scaledPixel[0] & 0xff00) >> 8, $scaledPixel[0] & 0xff, ($scaledPixel[0] & 0xff000000) >> 24); } imagesetpixel($newImage, $x * 2, $y * 2, $colors[$scaledPixel[0]]); if (!isset($colors[$scaledPixel[1]])) { $colors[$scaledPixel[1]] = imagecolorallocatealpha($newImage, ($scaledPixel[1] & 0xff0000) >> 16, ($scaledPixel[1] & 0xff00) >> 8, $scaledPixel[1] & 0xff, ($scaledPixel[1] & 0xff000000) >> 24); } imagesetpixel($newImage, $x * 2 + 1, $y * 2, $colors[$scaledPixel[1]]); if (!isset($colors[$scaledPixel[2]])) { $colors[$scaledPixel[2]] = imagecolorallocatealpha($newImage, ($scaledPixel[2] & 0xff0000) >> 16, ($scaledPixel[2] & 0xff00) >> 8, $scaledPixel[2] & 0xff, ($scaledPixel[2] & 0xff000000) >> 24); } imagesetpixel($newImage, $x * 2, $y * 2 + 1, $colors[$scaledPixel[2]]); if (!isset($colors[$scaledPixel[3]])) { $colors[$scaledPixel[3]] = imagecolorallocatealpha($newImage, ($scaledPixel[3] & 0xff0000) >> 16, ($scaledPixel[3] & 0xff00) >> 8, $scaledPixel[3] & 0xff, ($scaledPixel[3] & 0xff000000) >> 24); } imagesetpixel($newImage, $x * 2 + 1, $y * 2 + 1, $colors[$scaledPixel[3]]); } } }
<?php require "../php/gallery.php"; list($id, $caption, $description) = getImageInfo($_SERVER["REQUEST_URI"], $gallery); ?> <!doctype html> <!-- - - - - - - - - - - - - - - - - - - - - - - - --> <!-- Paradise ~ centerkey.com/paradise --> <!-- GPLv3 ~ Copyright (c) individual contributors --> <!-- - - - - - - - - - - - - - - - - - - - - - - - --> <html> <head> <meta charset=utf-8> <meta name=apple-mobile-web-app-title content="Gallery"> <title><?php echo $caption; ?> • <?php echo $settings->{"title"}; ?> </title> <link rel=icon href=http://centerkey.com/paradise/graphics/bookmark.png> <link rel=apple-touch-icon href="../../~data~/portfolio/<?php echo $id; ?> -small.png"> <link rel=stylesheet href=https://cdn.jsdelivr.net/fontawesome/4/css/font-awesome.min.css> <link rel=stylesheet href=https://cdn.jsdelivr.net/dna.js/0/dna.css> <link rel=stylesheet href=../../css/reset.css> <link rel=stylesheet href="../../css/style.css"> <link rel=stylesheet href="../../~data~/custom-style.css">
$ext = pathinfo($_FILES['file']['name']); $ext = strtolower($ext['extension']); $tempFile = $_FILES['file']['tmp_name']; $targetPath = AVATARS_PATH; if (!is_dir($targetPath)) { mkdir($targetPath, 0755, true); } $new_file_name = 'avatar-' . $user_id . '.' . $ext; $targetFile = $targetPath . $new_file_name; if (!in_array($ext, $filetype)) { $message = __('仅允许上传JPG、GIF、BMP、PNG图片', 'tinection'); } else { move_uploaded_file($tempFile, $targetFile); if (!file_exists($targetFile)) { $message = __('图片上传失败', 'tinection'); } elseif (!($imginfo = getImageInfo($targetFile))) { $message = __('图片不存在', 'tinection'); } else { $img = $new_file_name; resize($img); $message = __('头像上传成功', 'tinection'); $update_user_avatar = update_user_meta($user_id, 'tin_avatar', 'customize'); $update_user_avatar_img = update_user_meta($user_id, 'tin_customize_avatar', $img); } } } else { $update_user_avatar = update_user_meta($user_id, 'tin_avatar', sanitize_text_field($_POST['avatar'])); if (!is_wp_error($update_user_id) || $update_user_avatar) { $message = __('基本信息已更新', 'tinection'); } }
return $retval; } /* * Output JSON given the imageInfo associative array */ function outputJSON($imageInfo, $callback) { header('Content-type: text/plain'); $jsonOutput = json_encode($imageInfo); if ($callback) { $jsonOutput = $callback . '(' . $jsonOutput . ');'; } echo $jsonOutput; } // Get the image size and depth $imageInfo = getImageInfo($zipPath, $file); // Output json if requested if ('json' == $ext) { // $$$ we should determine the output size first based on requested scale outputJSON($imageInfo, $callback); exit; } // Unfortunately kakadu requires us to know a priori if the // output file should be .ppm or .pgm. By decompressing to // .bmp kakadu will write a file we can consistently turn into // .pnm. Really kakadu should support .pnm as the file output // extension and automatically write ppm or pgm format as // appropriate. $decompressToBmp = true; if ($decompressToBmp) { $stdoutLink = '/tmp/stdout.bmp';