当前位置: 首页>>代码示例>>PHP>>正文


PHP SimpleImage::crop方法代码示例

本文整理汇总了PHP中SimpleImage::crop方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleImage::crop方法的具体用法?PHP SimpleImage::crop怎么用?PHP SimpleImage::crop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SimpleImage的用法示例。


在下文中一共展示了SimpleImage::crop方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: cropImage

		function cropImage($imagePath, $width, $height) {
			global $module;
			
			$folderPath = $this->crop_folder;
			
			$parent_path = str_replace("/images/crop","",$folderPath);
			$parent_path = str_replace("\\images\\crop","",$parent_path);
			
			if(!JFolder::exists($parent_path)){
				if(mkdir($parent_path, 0777)){
				
				} else {
					echo "Error: Can't create folder for resize image!"; exit();
				}
			}
			
			$parent_path = str_replace("/crop","",$folderPath);
			$parent_path = str_replace("\\crop","",$parent_path);
			 if(!JFolder::exists($parent_path)){
					//if(JFolder::create($folderPath)){echo "ok";} else {echo "not ok";}	 
					if(mkdir($parent_path, 0777)){
						if(mkdir($folderPath, 0777)){
						
						} else {
							echo "Error: Can't create folder for crop image!"; 
						}	
					} else {
						echo "Error: Can't create folder for crop image!"; 
					}	 
			 } else
			 {
				 if(!JFolder::exists($folderPath)){
					if(mkdir($folderPath, 0777)){
						
					} else {
						echo "Error: Can't create folder for crop image!"; 
					}	
				 
				 }
			 }
			 
			$nameImg = str_replace('/','',strrchr($imagePath,"/")); 
			$ext = substr($nameImg, strrpos($nameImg, '.'));
			$file_name = substr($nameImg, 0,  strrpos($nameImg, '.'));
			$nameImg = str_replace(" ","",$file_name . "_" . $width . "_" . $height .  $ext);	 
			 
			 if(!JFile::exists($folderPath.DS.$nameImg)){
				 $image = new SimpleImage();
				 $image->load($imagePath);
				 $image->crop($width,$height);
				 $image->save($folderPath.DS.$nameImg);
			 }else{
					 list($info_width, $info_height) = @getimagesize($folderPath.DS.$nameImg);
					 if($width!=$info_width||$height!=$info_height){
						 $image = new SimpleImage();
						 $image->load($imagePath);
						 $image->crop($width,$height);
						 $image->save($folderPath.DS.$nameImg);
					 }
			 }
			 
			 return $this->url_to_crop . $nameImg;
		}
开发者ID:sergy444,项目名称:joomla,代码行数:63,代码来源:SotVm.php

示例2: cropImage

		function cropImage($imagePath, $width, $height) {
			global $module;
			
			$folderPath = $this->crop_folder;
	
			if(!JFolder::exists($folderPath)){
					JFolder::create($folderPath);	 
			}
			$nameImg = str_replace('/','',strrchr($imagePath,"/")); 
			$ext = substr($nameImg, strrpos($nameImg, '.'));
			$file_name = substr($nameImg, 0,  strrpos($nameImg, '.'));
			$nameImg = str_replace(" ","",$file_name . "_" . $width . "_" . $height .  $ext);	 
			 
			 if(!JFile::exists($folderPath.DS.$nameImg)){
				 $image = new SimpleImage();
				 $image->load($imagePath);
				 $image->crop($width,$height);
				 $image->save($folderPath.DS.$nameImg);
			 }else{
					 list($info_width, $info_height) = @getimagesize($folderPath.DS.$nameImg);
					 if($width!=$info_width||$height!=$info_height){
						 $image = new SimpleImage();
						 $image->load($imagePath);
						 $image->crop($width,$height);
						 $image->save($folderPath.DS.$nameImg);
					 }
			 }
			 
			 return $this->url_to_crop . $nameImg;
		}
开发者ID:sergy444,项目名称:joomla,代码行数:30,代码来源:Sotvm.php

示例3: cropPhoto

 public function cropPhoto()
 {
     $my = JFactory::getUser();
     $ajax = DiscussHelper::getHelper('Ajax');
     if (!$my->id) {
         $ajax->reject(JText::_('You are not allowed here'));
         return $ajax->send();
     }
     $config = DiscussHelper::getConfig();
     $profile = DiscussHelper::getTable('Profile');
     $profile->load($my->id);
     $path = rtrim($config->get('main_avatarpath'), DIRECTORY_SEPARATOR);
     $path = JPATH_ROOT . '/' . $path;
     $photoPath = $path . '/' . $profile->avatar;
     $originalPath = $path . '/' . 'original_' . $profile->avatar;
     // @rule: Delete existing image first.
     if (JFile::exists($photoPath)) {
         JFile::delete($photoPath);
     }
     $x1 = JRequest::getInt('x1');
     $y1 = JRequest::getInt('y1');
     $width = JRequest::getInt('width');
     $height = JRequest::getInt('height');
     if (is_null($x1) && is_null($y1) && is_null($width) && is_null($height)) {
         $ajax->reject(JText::_('Unable to crop because cropping parameters are incomplete!'));
         return $ajax->send();
     }
     require_once DISCUSS_CLASSES . '/simpleimage.php';
     $image = new SimpleImage();
     $image->load($originalPath);
     $image->crop($width, $height, $x1, $y1);
     $image->resize(160, 160);
     $image->save($photoPath);
     $path = trim($config->get('main_avatarpath'), '/') . '/' . $profile->avatar;
     $uri = rtrim(JURI::root(), '/');
     $uri .= '/' . $path;
     $ajax->resolve($uri, 'Avatar cropped successfully!');
     return $ajax->send();
 }
开发者ID:BetterBetterBetter,项目名称:B3App,代码行数:39,代码来源:view.ajax.php

示例4: cropImage

 function cropImage($imagePath, $width, $height)
 {
     global $module;
     $folderPath = $this->resize_folder;
     if (!JFolder::exists($folderPath)) {
         JFolder::create($folderPath);
     }
     $nameImg = "crop_" . $width . '__' . $height . str_replace('/', '', strrchr($imagePath, "/"));
     if (!JFile::exists($folderPath . DS . $nameImg)) {
         $image = new SimpleImage();
         $image->load($imagePath);
         $image->crop($width, $height);
         $image->save($folderPath . DS . $nameImg);
     } else {
         list($info_width, $info_height) = @getimagesize($folderPath . DS . $nameImg);
         if ($width != $info_width || $height != $info_height) {
             $image = new SimpleImage();
             $image->load($imagePath);
             $image->crop($width, $height);
             $image->save($folderPath . DS . $nameImg);
         }
     }
     return $this->url_to_resize . $nameImg;
 }
开发者ID:skyview059,项目名称:e-learning-website,代码行数:24,代码来源:ytc_content.php

示例5: SimpleImage

}
header('Content-Type: image/jpeg');
$image = new SimpleImage();
$style = strtolower($style);
switch ($style) {
    case 'tmb':
        $image->load("models/{$model}/{$p_img}");
        $image->SetWatermark();
        $image->resizeToHeight(100);
        $image->output();
        break;
    case 'profile':
        //$image->load("models/$model/$p_img");
        $image->load("models/{$p_img}");
        $image->resizeToHeight(407);
        $image->crop(237);
        $image->SetWatermark();
        $image->output();
        break;
    case 'main':
        //$image->load("models/$model/$p_img");
        $image->load("models/{$p_img}");
        $image->resizeToHeight(402);
        // 217x402
        $image->crop(217);
        $image->SetWatermark();
        $image->output();
        break;
    case 'full':
        $image->load("models/{$model}/{$p_img}");
        $image->resizeToHeight(600);
开发者ID:badgames,项目名称:DRLG,代码行数:31,代码来源:getImage.php

示例6: cropImage

 function cropImage($imagePath, $width, $height, $id, $suffix = '')
 {
     global $module;
     $folderPath = $this->resize_folder;
     if (!JFolder::exists($folderPath)) {
         JFolder::create($folderPath);
     }
     $nameImg = $id . "_" . $file_name . $suffix . $ext;
     if (!JFile::exists($folderPath . DS . $nameImg)) {
         $image = new SimpleImage();
         $image->load($imagePath);
         $image->crop($width, $height);
         $image->save($folderPath . DS . $nameImg);
     } else {
         list($info_width, $info_height) = @getimagesize($folderPath . DS . $nameImg);
         if ($width != $info_width || $height != $info_height) {
             $image = new SimpleImage();
             $image->load($imagePath);
             $image->crop($width, $height);
             $image->save($folderPath . DS . $nameImg);
         }
     }
     return $this->url_to_resize . $nameImg;
 }
开发者ID:naquib555,项目名称:quBitolgy,代码行数:24,代码来源:contentslider.php

示例7: makeProfilePicture

 function makeProfilePicture($photo_id)
 {
     $this->layout = 'blue_full_block';
     if (!empty($this->data)) {
         $this->loadModel('MemberProfile');
         $this->loadModel('PhotoUpdate');
         $this->loadModel('Album');
         $member_id = $this->Session->read('Member.id');
         $photo = $this->Photo->getPhotoInfo($photo_id);
         $albumName = $this->Photo->Album->getAlbumInfo($photo['Photo']['album_id'], 'name');
         $imageDir = $this->getUploadDir($member_id, $albumName);
         $imageFile = $imageDir . '/' . $photo['Photo']['picture_path'];
         //measurements used in cropping
         $x1 = $this->data['Photo']['x1'];
         $y1 = $this->data['Photo']['y1'];
         $width = $this->data['Photo']['width'];
         $height = $this->data['Photo']['height'];
         //location of the images.. directory of profile pictures
         $profileDir = $this->getUploadDir($member_id, $this->profileAlbum);
         $picturePath = $this->randomString();
         //create cropped copy of image
         $cropCopy = new SimpleImage();
         $cropCopy->load($imageFile);
         $cropCopy->crop($x1, $y1, $width, $height);
         $ext = $cropCopy->ext();
         //extension name
         $profileCrop = $profileDir . '/profile_thumb_' . $picturePath . $ext;
         //the cropped copy of image file
         $cropCopy->save($profileCrop);
         /*//create full copy of image
         		$fullCopy = new SimpleImage();
         		$fullCopy->load($imageFile);
         		$profileFull = $profileDir . '/' . $picturePath . $ext; //the full copy of image file 
         		$fullCopy->save($profileFull);*/
         //create thumbnail copy of image
         $thumbCopy = new SimpleImage();
         $thumbCopy->load($profileCrop);
         $thumbCopy->resize(155, 115);
         $profileThumb = $profileDir . '/thumb_' . $picturePath . $ext;
         //the cropped copy of image file
         $thumbCopy->save($profileThumb);
         //save picture_path on members profile.. table used to get the profile picture
         $member = $this->MemberProfile->find('first', array('conditions' => array('member_id' => $member_id), 'fields' => array('MemberProfile.id'), 'recursive' => -1));
         $this->MemberProfile->id = $member['MemberProfile']['id'];
         $this->MemberProfile->saveField('picture_path', '' . $picturePath . $ext);
         //save path to profile picture folder..
         $profile = $this->Photo->Album->find('first', array('conditions' => array('Album.member_id' => $member_id, 'Album.name' => $this->profileAlbum), 'fields' => array('Album.id'), 'recursive' => -1));
         /*$this->Photo->id = $photo_id;
         		$this->Photo->saveField('profile_pic', 1);*/
         $photo['Photo']['id'] = null;
         //reset the id to create new record
         $photo['Photo']['album_id'] = $profile['Album']['id'];
         $photo['Photo']['picture_path'] = $picturePath . $ext;
         $photo['Photo']['profile_pic'] = 1;
         //assign cover picture if no photo was set yet
         if ($this->Album->getCoverPicture($photo['Photo']['album_id']) == false) {
             $photo['Photo']['cover_pic'] = 1;
         }
         //save update..
         if ($this->Photo->save($photo)) {
             $album_id = $this->Photo->getPhotoInfo($photo_id, 'album_id');
             $this->Album->saveUpdate($album_id, 1);
         }
         $this->redirect(array('controller' => 'photos', 'action' => 'view', $member_id));
     } else {
         $this->redirect(array('controller' => 'photos', 'action' => 'view', $member_id));
     }
 }
开发者ID:redhattaccoss,项目名称:Qalanjo,代码行数:68,代码来源:photos_controller.php

示例8: validateSponsorImage

 /**
  * Verify and validate the extension of the uploaded file.
  *
  * @param string $name
  * @param string $type
  * @return boolean
  */
 public function validateSponsorImage($name, $tmpName, $type)
 {
     $allowedExtensions = array("gif", "jpeg", "jpg", "png", "pdf", "GIF", "JPEG", "JPG", "PNG", "PDF");
     $temp = explode(".", $name);
     $extension = end($temp);
     if (($type === "image/gif" || $type === "image/jpeg" || $type === "image/jpg" || $type === "image/pjpeg" || $type === "image/x-png" || $type === "image/png" || $type === "application/pdf") && in_array($extension, $allowedExtensions)) {
         $img = new SimpleImage($tmpName);
         $img->fit_to_width(360);
         $img->invert();
         $img->crop(0, ($img->get_height() - 190) / 2, 360, ($img->get_height() - 190) / 2 + 190);
         $img->invert();
         $img->save("_temp/_img.png");
         return true;
     } else {
         return false;
     }
 }
开发者ID:KINOTO,项目名称:apymeco,代码行数:24,代码来源:SponsorModel.php

示例9: resizeImage

 public static function resizeImage($file, $folder, $width = 120, $height = 120, $iparams = array(), $loc_ext_name_com = null)
 {
     global $ext_name, $ext_name_com;
     $loc_ext_name_com = !empty($loc_ext_name_com) ? $loc_ext_name_com : $ext_name_com;
     $params = JComponentHelper::getParams($loc_ext_name_com);
     if (!isset($iparams['displace'])) {
         $iparams['displace'] = $params->get('displace', 0);
     }
     if (!isset($iparams['watermark'])) {
         $iparams['watermark'] = $params->get('watermark', 0);
     }
     if (!isset($iparams['halign'])) {
         $iparams['halign'] = $params->get('halign', 'center');
     }
     if (!isset($iparams['valign'])) {
         $iparams['valign'] = $params->get('valign', 'middle');
     }
     $iparams['watermark_type'] = $params->get('watermark_type', 0);
     $iparams['watermark_valign'] = $params->get('watermark_valign', 'middle');
     $iparams['watermark_halign'] = $params->get('watermark_halign', 'center');
     $iparams['background_type'] = $params->get('background_type', 'file');
     natsort($iparams);
     $dst_file = basename($file);
     foreach ($iparams as $iparam) {
         $dst_file = JString::str_ireplace('/', '.', $iparam) . '-' . $dst_file;
     }
     if (!class_exists('SimpleImage')) {
         require dirname(__FILE__) . DS . '..' . DS . 'additional' . DS . 'simpleimage.php';
     }
     /*
             if($width == 0) {
                 $width = $params->get('thumb_width', 120);
             }*/
     if ($height == 0) {
         $height = $params->get('thumb_height', 120);
     }
     $dst_path_segments = array('media', $loc_ext_name_com, 'images', $folder, 'w' . $width . 'x' . 'h' . $height);
     $dst_path = JPATH_ROOT;
     foreach ($dst_path_segments as $v) {
         $dst_path .= DS . $v;
         if (!JFolder::exists($dst_path)) {
             JFolder::create($dst_path);
             chmod($dst_path, 0777);
         }
     }
     $file != '' ? $dst_filename = $dst_path . DS . $dst_file : ($dst_filename = $dst_path . DS . 'no.jpg');
     if (!JFile::exists($dst_filename)) {
         if ($file != '') {
             $src_filename = JPATH_ROOT . DS . 'media' . DS . $loc_ext_name_com . DS . 'images' . DS . $folder . DS . 'original' . DS . basename($file);
         } else {
             $src_filename = JPATH_ROOT . DS . 'media' . DS . $loc_ext_name_com . DS . 'images' . DS . $folder . DS . 'no.jpg';
         }
         if (!JFile::exists($src_filename)) {
             $src_filename = JPATH_ROOT . DS . 'media' . DS . $loc_ext_name_com . DS . 'images' . DS . $folder . DS . 'no.jpg';
         }
         $image = new SimpleImage($src_filename);
         if ($width == 0) {
             $ratio = $height / $image->get_height();
             $width = $image->get_width() * $ratio;
         }
         if ($image->get_width() > $width || $image->get_height() > $height) {
             $ratio_in = $image->get_width() / $image->get_height();
             if ($iparams['displace'] == 0) {
                 $ratio_out = $width / $height;
                 if ($ratio_in > $ratio_out) {
                     $image->resize((int) $width * $ratio_in, $height);
                 } else {
                     $image->resize($width, $width / $ratio_in);
                 }
                 $x1 = 0;
                 $y1 = 0;
                 switch ($iparams['halign']) {
                     case 'center':
                         $x1 = round($image->get_width() / 2 - $width / 2);
                         break;
                     case 'right':
                         $x1 = round($image->get_width() - $width);
                         break;
                 }
                 switch ($iparams['valign']) {
                     case 'middle':
                         $y1 = round($image->get_height() / 2 - $height / 2);
                         break;
                     case 'bottom':
                         $y1 = round($image->get_height() - $height);
                         break;
                 }
                 $image->crop($x1, $y1, $x1 + $width, $y1 + $height);
             } else {
                 if ($width / $ratio_in > $height) {
                     $image->resize($height * $ratio_in, $height);
                 } else {
                     $image->resize($width, $width / $ratio_in);
                 }
             }
         }
         if ($iparams['watermark'] == 1) {
             $watermark_image = $params->get('watermark_image', '');
             if (file_exists(JPATH_ROOT . DS . $watermark_image) && is_file(JPATH_ROOT . DS . $watermark_image)) {
                 $image->watermark(JPATH_ROOT . DS . $watermark_image, $iparams);
//.........这里部分代码省略.........
开发者ID:JexyRu,项目名称:Ksenmart,代码行数:101,代码来源:media.php


注:本文中的SimpleImage::crop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。