public static function resize($strFileName = "", $intWidth = 100, $intHeight = 75, $intTemplate = RESIZE_EXACT, $intQuality = 75, $blnOverwrite = FALSE, $strName = "", $blnToScreen = FALSE, $blnGrayscale = FALSE) { $strReturn = $strName; if (empty($strReturn)) { if (!$blnOverwrite) { //*** Generate a random name. $strExtension = self::getExtension(basename($strFileName)); $strReturn = dirname($strFileName) . "/{$intWidth}x{$intHeight}_" . basename($strFileName, $strExtension) . "_" . strtotime("now") . "{$strExtension}"; } else { $strReturn = $strFileName; } } $objEditor = new ImageEditor(basename($strFileName), dirname($strFileName) . "/"); switch ($intTemplate) { case RESIZE_CROP: //*** Don't blow the image up if it is smaller then the destination. if ($intWidth > $objEditor->getWidth() && $intHeight > $objEditor->getHeight()) { //*** Skip the resize. } else { $destX = ($objEditor->getWidth() - $intWidth) / 2; $destY = ($objEditor->getHeight() - $intHeight) / 2; $objEditor->crop(round($destX), round($destY), $intWidth, $intHeight); } break; case RESIZE_FIT_CROP: //*** Resize the image to fit into the boundary box. //*** Portrait source. $destWidth = $intWidth; $destHeight = $destWidth / $objEditor->getWidth() * $objEditor->getHeight(); if ($destHeight < $intHeight) { //*** Landscape source. $destHeight = $intHeight; $destWidth = $destHeight / $objEditor->getHeight() * $objEditor->getWidth(); } //*** Don't blow the image up if it is smaller then the destination. if (round($destWidth) > $objEditor->getWidth() && round($destHeight) > $objEditor->getHeight()) { //*** Skipt the resize. $destX = ($objEditor->getWidth() - $intWidth) / 2; $destY = ($objEditor->getHeight() - $intHeight) / 2; $objEditor->crop(round($destX), round($destY), $intWidth, $intHeight); } else { $objEditor->resize(round($destWidth), round($destHeight)); $destX = ($objEditor->getWidth() - $intWidth) / 2; $destY = ($objEditor->getHeight() - $intHeight) / 2; $objEditor->crop(round($destX), round($destY), $intWidth, $intHeight); } break; case RESIZE_DISTORT: //*** Don't blow the image up if it is smaller then the destination. if ($intWidth > $objEditor->getWidth() && $intHeight > $objEditor->getHeight()) { //*** Skipt the resize. } else { $objEditor->resize($intWidth, $intHeight); } break; case RESIZE_EXACT: $destWidth = $intWidth; $destHeight = $destWidth / $objEditor->getWidth() * $objEditor->getHeight(); if ($destHeight > $intHeight) { //*** Landscape source. $destHeight = $intHeight; $destWidth = $destHeight / $objEditor->getHeight() * $objEditor->getWidth(); } //*** Don't blow the image up if it is smaller then the destination. if (round($destWidth) > $objEditor->getWidth() && round($destHeight) > $objEditor->getHeight()) { //*** Skipt the resize. } else { $objEditor->resize(round($destWidth), round($destHeight)); } break; } if ($blnGrayscale) { $objEditor->grayscale(); } if (!empty($strReturn)) { if ($blnToScreen) { //*** Return image. $objEditor->outputImage($intQuality); } else { //*** Write file to disk. $objEditor->outputFile(basename($strReturn), dirname($strReturn) . "/", $intQuality); } } return $strReturn; }
function change_image($nazwa, $katalog, $w, $h, $new_nazwa = "") { if (file_exists($katalog . "/" . $nazwa)) { $plik = $katalog . "/" . $nazwa; } else { $plik = ""; } if (strlen($plik) > 0 && ($w > 0 || $h > 0)) { list($old_w, $old_h) = getimagesize($plik); $image = new ImageEditor($nazwa, $katalog); if ($w > 0 && $h == 0) { $new_w = $w; $new_h = ceil($new_w * $old_h / $old_w); $image->resize($new_w, $new_h); } else { if ($h > 0 && $w == 0) { $new_h = $h; $new_w = ceil($new_h * $old_w / $old_h); $image->resize($new_w, $new_h); } else { if ($h > 0 && $w > 0) { $image->resize($w, $h); } } } if (strlen($new_nazwa) > 0) { $image->outputFile($new_nazwa, $katalog . "/"); chmod($katalog . "/" . $new_nazwa, 0644); } else { $image->outputFile($nazwa, $katalog . "/"); chmod($katalog . "/" . $nazwa, 0644); } } }
$objImageupload = new imageFileUpload(); $objImageupload->tag_name = "file_name"; $a_tempFileName = explode(".", strtolower($_FILES['file_name']['name'])); $objImageupload->file_name = $a_tempFileName[0] . "." . $a_tempFileName[1]; $newFileName = $objImageupload->file_name; $objImageupload->storing_directory = IMAGE_UPLOAD_PATH; $objImageupload->image_extensions = "jpg,gif,png,jpeg"; if (false == $objImageupload->upload()) { $error = $objImageupload->errorMsg(); echo "Error : " . $error; } $outputFileName = $objImageupload->file_name; $destinationPath = $objImageupload->storing_directory; $objImageEditor = new ImageEditor($objImageupload->file_name, $objImageupload->storing_directory); $objImageEditor->resizeInProportion($objImageEditor->getWidth(), $objImageEditor->getHeight(), 320); $objImageEditor->outputFile($outputFileName, $destinationPath); chmod($objImageupload->storing_directory . $objImageupload->file_name, 0777); /* $image_height = 320; $image_width = 400; $arfilename = $objUpload->upload($id,'file_name',IMAGE_UPLOAD_PATH,'jpeg,gif,png,JPG,JPEG,jpeg'); $filename = $arfilename[0]; //$objUpload->smart_resize_image(IMAGE_UPLOAD_PATH.$arfilename[0],$image_height,$image_width,IMAGE_UPLOAD_PATH,true,$arfilename[0],false); */ // $image->load(IMAGE_UPLOAD_PATH.$arfilename[0]); // $image->resize(320,316); // $image->save(IMAGE_UPLOAD_PATH.$arfilename[0]); // $WaterMarkText = "fototime.com"; // $image->watermarkImage (IMAGE_UPLOAD_PATH.$arfilename[0], $WaterMarkText, //IMAGE_UPLOAD_PATH.$arfilename[0]); include "../classes/imageslice.php"; $slice = new ImageSlicer($id, IMAGE_UPLOAD_PATH . $objImageupload->file_name, 1, 4);
function tb_post_thumb($generate = false, $alt_text = '', $resize_width = 0, $resize_height = 0, $crop_x = 0, $crop_y = 0, $entry = null) { global $post; if ($entry) { $post = $entry; } $settings = get_option('post_thumbnail_settings'); if ($resize_width) { $settings['resize_width'] = $resize_width; } if ($resize_height) { $settings['resize_height'] = $resize_height; } // find an image from your domain if (preg_match('/<img (.*?)src="https?:\\/\\/(www\\.)?' . str_replace('/', '\\/', $settings['domain_name']) . '\\/(.*?)"/i', $post->post_content, $matches)) { // put matches into recognizable vars // fix later, assumes document root will match url structure $the_image = $settings['base_path'] . '/' . $matches[3]; // check if image exists on server // if doesn't exist, can't do anything so return default image if (!file_exists($the_image)) { return tb_post_thumb_gen_image(str_replace($settings['full_domain_name'], $settings['base_path'], $settings['default_image']), $settings['default_image'], $alt_text, $generate); } $dest_path = pathinfo($the_image); // dir to save thumbnail to $save_dir = $dest_path['dirname'] . "/{$settings['folder_name']}"; // name to save to $filename_suffix = $resize_width . 'x' . $resize_height . '-' . $crop_x . '-' . $crop_y; $filename = substr($dest_path['basename'], 0, strrpos($dest_path['basename'], ".")); if ($settings['append'] == 'true') { $rename_to = $filename . $settings['append_text'] . '-' . $filename_suffix . '.' . $dest_path['extension']; } else { $rename_to = $settings['append_text'] . $filename . '-' . $filename_suffix . '.' . $dest_path['extension']; } // check if file already exists // return location if does if (file_exists($save_dir . '/' . $rename_to)) { $imagelocation = str_replace($settings['base_path'], $settings['full_domain_name'], $save_dir . '/' . $rename_to); return tb_post_thumb_gen_image($save_dir . '/' . $rename_to, $imagelocation, $alt_text, $generate); } // sticky bit? if (!is_dir($save_dir)) { mkdir($save_dir, 0777); } // manipulate thumbnails $thumb = new ImageEditor($dest_path['basename'], $dest_path['dirname'] . '/'); $thumb->resize($settings['resize_width'], $settings['resize_height'], $settings['keep_ratio']); if ($settings['crop_exact'] == 'true' || $crop_x != 0 && $crop_y != 0) { if ($crop_x != 0 && $crop_y != 0) { $settings['resize_width'] = $crop_x; $settings['resize_height'] = $crop_y; } if ($thumb->x > $settings['resize_width'] || $thumb->y > $settings['resize_height']) { $thumb->crop((int) (($thumb->x - $settings['resize_width']) / 2), 0, $settings['resize_width'], $settings['resize_height']); } } $thumb->outputFile($save_dir . "/" . $rename_to, ""); chmod($save_dir . "/" . $rename_to, 0666); $imagelocation = str_replace($settings['base_path'], $settings['full_domain_name'], $save_dir . '/' . $rename_to); return tb_post_thumb_gen_image($save_dir . '/' . $rename_to, $imagelocation, $alt_text, $generate); } else { if (!empty($settings['video_regex']) && tb_post_thumb_check_video($settings['video_regex'])) { $settings['default_image'] = $settings['video_default']; } return tb_post_thumb_gen_image(str_replace($settings['full_domain_name'], $settings['base_path'], $settings['default_image']), $settings['default_image'], $alt_text, $generate); } }
/** * Executes RotateImage action * * This action can be used into an ajax action to rotate an image. This function requires * some parameters: * image : The name of the image to resize * imagePath : The full image path * degrees : The angle value for rotation. It can be 90, 180, 270 * imageType : The new image type. This parameter must be 1-GIF 2-JPG 3-PNG. Other * formats will be ignored * imageQuality : The new value for the image quality. Applies only to JPG images * * return A JSon header. */ public function executeRotateImage() { $imageEditor = new ImageEditor($this->getRequestParameter('image'), sfConfig::get('app_images_path')); $imageEditor->rotate($this->getRequestParameter('degrees')); $imageEditor->outputFile($this->getRequestParameter('image'), sfConfig::get('app_images_path'), $this->getRequestParameter('imageType'), $this->getRequestParameter('imageQuality')); // Produces the output header for ajax calling. $output = ''; if ($this->getRequestParameter('previewWidth') != 0 && $this->getRequestParameter('previewHeight') != 0) { $imageAttributes = w3sClassImageManager::getImageAttributes($this->getRequestParameter('image'), $this->getRequestParameter('previewWidth'), $this->getRequestParameter('previewHeight'), $this->getRequestParameter('setCanvas')); $output = '[["w3s_image_size", "' . $imageAttributes["size"] . '"],["w3s_image_width", "' . $imageAttributes["width"] . '"],["w3s_image_height", "' . $imageAttributes["height"] . '"],["w3s_image_preview", "' . $imageAttributes["image"] . '"],["w3s_image_canvas", "' . $imageAttributes["canvas"] . '"],["w3s_start_width", "' . $imageAttributes["width"] . '"],["w3s_start_height", "' . $imageAttributes["height"] . '"]]'; } $this->getResponse()->setHttpHeader("X-JSON", '(' . $output . ')'); return sfView::HEADER_ONLY; }