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; }
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; }
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(); }
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; }
} 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);
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; }
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)); } }
/** * 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; } }
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); } } $bg_file = $params->get('background_file', ''); $image->background($width, $height, $iparams, $bg_file, $params->get('background_color', 'ffffff')); //$image->best_fit($width, $height); if ($iparams['background_type'] == 'file' && (empty($bg_file) || !empty($bg_file) && !file_exists(JPATH_ROOT . DS . $file))) { $image->save($dst_filename, 'png'); } else { $image->save($dst_filename); } } return JURI::root() . str_replace(JPATH_ROOT . DS, '', $dst_filename); }