/** * Show image using image details. * * @since 1.0.0 * @package GeoDirectory * @param array|object $request Image info either as an array or object. * @param string $size Optional. Thumbnail size. Default: thumbnail. * @param bool $no_image Optional. Do you want to return the default image when no image is available? Default: false. * @param bool $echo Optional. Do you want to print it instead of returning it? Default: true. * @return bool|string Returns image html. */ function geodir_show_image($request = array(), $size = 'thumbnail', $no_image = false, $echo = true) { $image = new stdClass(); $html = ''; if (!empty($request)) { if (!is_object($request)) { $request = (object) $request; } @(list($width, $height) = getimagesize($request->path)); $image->src = $request->src; $image->width = $width; $image->height = $height; $max_size = (object) geodir_get_imagesize($size); if (!is_wp_error($max_size)) { if ($image->width) { if ($image->height >= $image->width) { $width_per = round($image->width * ($max_size->h / $image->height) / $max_size->w * 100, 2); } elseif ($image->width < $max_size->h) { $width_per = round($image->width / $max_size->w * 100, 2); } else { $width_per = 100; } } //$html = '<div class="geodir_thumbnail" style="background-image:url(\''.$image->src.'\');"></div>'; //$html = '<div class="geodir_thumbnail"><img style="max-height:'. $max_size->h .'px;" alt="place image" src="' . $image->src . '" /></div>'; //print_r($_REQUEST); if (is_admin() && !isset($_REQUEST['geodir_ajax'])) { $html = '<div class="geodir_thumbnail"><img style="max-height:' . $max_size->h . 'px;" alt="place image" src="' . $image->src . '" /></div>'; } else { $html = '<div class="geodir_thumbnail" style="background-image:url(\'' . $image->src . '\');"></div>'; } /*$html = '<div style="text-align: center;max-height:'.$max_size->h.'px;line-height:'.$max_size->h.'px;">'; $html .= '<img src="' . $image->src . '" style="vertical-align:middle;max-height:'. $max_size->h .'px;margin:-2px auto 0;'; $html .= 'max-width:'.$width_per.'%'; $html .= '" /></div>'; */ } } if (!empty($html) && $echo) { echo $html; } elseif (!empty($html)) { return $html; } else { return false; } }
/** * Show image using image details. * * @since 1.0.0 * @package GeoDirectory * @param array|object $request Image info either as an array or object. * @param string $size Optional. Thumbnail size. Default: thumbnail. * @param bool $no_image Optional. Do you want to return the default image when no image is available? Default: false. * @param bool $echo Optional. Do you want to print it instead of returning it? Default: true. * @return bool|string Returns image html. */ function geodir_show_image($request = array(), $size = 'thumbnail', $no_image = false, $echo = true) { $image = new stdClass(); $html = ''; if (!empty($request)) { if (!is_object($request)) { $request = (object) $request; } if (isset($request->src) && !isset($request->path)) { $request->path = $request->src; } /* * getimagesize() works faster from path than url so we try and get path if we can. */ $upload_dir = wp_upload_dir(); $img_no_http = str_replace(array("http://", "https://"), "", $request->path); $upload_no_http = str_replace(array("http://", "https://"), "", $upload_dir['baseurl']); if (strpos($img_no_http, $upload_no_http) !== false) { $request->path = str_replace($img_no_http, $upload_dir['basedir'], $request->path); } @(list($width, $height) = getimagesize($request->path)); $image->src = $request->src; $image->width = $width; $image->height = $height; $max_size = (object) geodir_get_imagesize($size); if (!is_wp_error($max_size)) { if ($image->width) { if ($image->height >= $image->width) { $width_per = round($image->width * ($max_size->h / $image->height) / $max_size->w * 100, 2); } elseif ($image->width < $max_size->h) { $width_per = round($image->width / $max_size->w * 100, 2); } else { $width_per = 100; } } if (is_admin() && !isset($_REQUEST['geodir_ajax'])) { $html = '<div class="geodir_thumbnail"><img style="max-height:' . $max_size->h . 'px;" alt="place image" src="' . $image->src . '" /></div>'; } else { $html = '<div class="geodir_thumbnail" style="background-image:url(\'' . $image->src . '\');"></div>'; } } } if (!empty($html) && $echo) { echo $html; } elseif (!empty($html)) { return $html; } else { return false; } }