function screenshots($video, $name) { $retval = false; if (is_file($video)) { include_once PATH_CLASS . '/CImageMagick.php'; $im =& CImageMagick::getInstance(); $name = substr($name, 0, strrpos($name, '.')); $safeNameM = NOW . '_' . preg_replace('/\\W/', '_', $name) . '_400x300.jpg'; $safePathM = PATH_FOTOROOT . '/thumbnail/' . FF_YM_STAMP . '/' . $safeNameM; exec($ffmpeg = 'ffmpeg -i ' . $video . ' -s 400x300 -vframes 10 -f image2 ' . $safePathM); $im->image($safePathM); $safeNameT1 = NOW . '_' . preg_replace('/\\W/', '_', $name) . '_75x75.jpg'; $safeNameT2 = NOW . '_' . preg_replace('/\\W/', '_', $name) . '_115x50.jpg'; $safeNameT3 = NOW . '_' . preg_replace('/\\W/', '_', $name) . '_150x100.jpg'; $safePathT = PATH_FOTOROOT . '/thumbnail/' . FF_YM_STAMP . '/'; $im->crop(75, 75, $safePathT . $safeNameT1); $im->crop(115, 50, $safePathT . $safeNameT2); $im->crop(150, 100, $safePathT . $safeNameT3); $basePath = '/thumbnail/' . FF_YM_STAMP . '/'; $retval = array('400x300' => $basePath . $safeNameM, '150x100' => $basePath . $safeNameT3, '115x50' => $basePath . $safeNameT2, '75x75' => $basePath . $safeNameT1); } return $retval; }
function _upload($src = false, $dest = false, $width = false, $height = false, $type = false) { include_once PATH_CLASS . '/CImageMagick.php'; $this->im =& CImageMagick::getInstance(); $dir = dirname($dest); $base = $this->fb->safename(basename($dest)); $ext = substr($base, strrpos($base, '.')); if (stristr($ext, '.jpg') === false && stristr($ext, '.jpeg') === false) { $base_convert = preg_replace('/\\.\\w*?$/', '.jpg', $base); } copy($src, $dest); if (isset($base_convert)) { $this->im->convert($dest, $dir . '/' . $base_convert); unlink($dest); $dest = $dir . '/' . $base_convert; } if ($width !== false && $height !== false) { if ($type == 'thumb') { $this->im->square($dest); } $this->im->image($dest); $this->im->scale($width, $height); } return str_replace(PATH_FOTOROOT, '', $dest); }
if (!file_exists($fullPath)) { $im =& CImageMagick::getInstance(); $fp = fopen($fullPath, 'w+'); $s3Path = str_replace(array(PATH_HOMEROOT, 'photos/base/'), array('', 'original/'), $fullPath); $s3Url = "http://s3.photos.jaisenmathai.com{$s3Path}"; $ch = curl_init($s3Url); curl_setopt($ch, CURLOPT_FILE, $fp); $data = curl_exec($ch); curl_close($ch); fclose($fp); $im->image($fullPath); $im->scale(FF_BASE_WIDTH, FF_BASE_HEIGHT); } if (file_exists($fullPath) && strlen($imageKey) == 32 && (strcasecmp('.jpg', $iExt) == 0 || strcasecmp('.jpeg', $iExt) == 0)) { $ie =& CImageEditor::getInstance(); $im =& CImageMagick::getInstance(); $fb =& CFotobox::getInstance(); $fbm =& CFotoboxManage::getInstance(); // check to see if a "base" version exists and generate from that if (file_exists($basePath = str_replace('/original/', '/base/', $fullPath))) { $fullPath = $basePath; } copy($fullPath, $tmpPath = PATH_HOMEROOT . PATH_TMP . '/' . md5($_SERVER['REDIRECT_QUERY_STRING'] . $_SERVER['REQUEST_URI']) . '-' . mt_rand()); $fotoData = $fb->fotoData($imageKey); $ie->setUser($fotoData['P_U_ID']); $ie->loadImage($fotoData['P_ID'], $tmpPath); $ie->applyHistoryToDynamic($tmpPath); $fbm->addDynamic($fotoData['P_U_ID'], $fotoData['P_ID'], str_replace(PATH_FOTO, '', $iDest), $iWidth, $iHeight, $_SERVER['REMOTE_ADDR']); // create handles for temp file and output file $iOrigHandle = imagecreatefromjpeg($tmpPath); $iOriginalWidth = imagesx($iOrigHandle);
function crop($foto_id = false, $x1 = 0, $y1 = 0, $x2 = false, $y2 = false) { $retval = false; if ($x2 !== false && $y2 !== false) { include_once PATH_CLASS . '/CImageMagick.php'; include_once PATH_CLASS . '/CFotobox.php'; include_once PATH_CLASS . '/CFotoboxManage.php'; $tmp_src = $this->temp(); $fb =& CFotobox::getInstance(); $im =& CImageMagick::getInstance(); $foto_data = $fb->fotoData($foto_id); $tmp = explode('/', $foto_data['P_THUMB_PATH']); $stamp = $tmp[2]; $fbm =& CFotoboxManage::getInstance(); $fbm->setStamp($stamp); if ($foto_data['P_ROTATION'] != 0) { $im->rotate($tmp_src, $tmp_src, $foto_data['P_ROTATION']); } $src = @getimagesize($tmp_src); if ($src[0] > FF_WEB_WIDTH || $src[1] > FF_WEB_HEIGHT) { if ($src[0] / FF_WEB_WIDTH == $src[1] / FF_WEB_HEIGHT) { $web_w = FF_WEB_WIDTH; $web_h = FF_WEB_HEIGHT; } else { if ($src[0] / FF_WEB_WIDTH > $src[1] / FF_WEB_HEIGHT) { $web_w = FF_WEB_WIDTH; $web_h = $src[1] * (FF_WEB_WIDTH / $src[0]); } else { if ($src[0] / FF_WEB_WIDTH < $src[1] / FF_WEB_HEIGHT) { $web_w = $src[0] * (FF_WEB_HEIGHT / $src[1]); $web_h = FF_WEB_HEIGHT; } } } } else { $web_w = $src[0]; $web_h = $src[1]; } $w_ratio = $src[0] / $web_w; $h_ratio = $src[1] / $web_h; $width = abs($x1 - $x2); $height = abs($y1 - $y2); $x = $x1 < $x2 ? $x1 : $x2; $y = $y1 < $y2 ? $y1 : $y2; $x = intval($x * $w_ratio); $y = intval($y * $h_ratio); $width = intval($width * $w_ratio); $height = intval($height * $h_ratio); $cmd = "-crop {$width}x{$height}+{$x}+{$y}"; exec("{$this->_convert} {$cmd} {$tmp_src} {$tmp_src}"); $fbm->update(array('up_id' => $foto_id, 'up_width' => $width, 'up_height' => $height)); $fbm->uploadThumbnail($tmp_src, $this->_image_name); $this->_applyHistory(); $this->_saveToHistory($cmd); $fbm->removeDynamics($foto_data['P_ID'], $foto_data['P_U_ID'], true); // false user_id true force $retval = array($width, $height); } return $retval; }