URL에서 이미지의 크기를 조정하거나 리샘플링 할 수있는 코드가 제공됩니다. 내 웹 사이트에서이 코드를 구현하고 싶습니다. resample 스크립트는 매우 간단하지만 실제로 웹 사이트의 다른 부분과 어떻게 작동하는지 모릅니다. 누군가가이 문제를 도와 주길 바랍니다.리 스크립트 스크립트, 다른 img URL을 사용하여 기존 웹 사이트에서 작동시키는 방법
$img_attributes= 'style="max-height: 100px; max-width: 100px"' . ' title="' . htmlspecialchars($product['product_name']) . '"';
이것은 이미지 리샘플링 할 수있는 코드는이 후 아래쪽의 코드의 일부이고, 썸네일은 다음과 같다 생성 코드 :
은<?php
// The file
$filename = 'http://valplibrary.files.wordpress.com/2009/01/5b585d_merry-christmas-blue-style.jpg';
$percent = 0.5; // percentage of resize
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output
imagejpeg($image_p, null, 100);
?>
이것은 내 웹 사이트의 thumnails에 부분적으로 책임이있는 전체 코드입니다.
<?php
if(!defined('_VALID_MOS') && !defined('_JEXEC')) die('Direct Access to '.basename(__FILE__).' is not allowed.');
/**
* This is the theme's function file.
* It allows you to declare additional functions and classes
* that may be used in your templates
*
* @version $Id: theme.php 1427 2008-06-18 20:04:01Z soeren_nb $
* @package VirtueMart
* @subpackage themes
* @copyright Copyright (C) 2006-2008 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_virtuemart/COPYRIGHT.php for copyright notices and details.
*
* http://virtuemart.net
*/
global $mainframe;
// include the stylesheet for this template
$vm_mainframe->addScriptDeclaration("window.templatePath = '".JURI::base()."';");
$vm_mainframe->addStyleSheet(VM_THEMEURL.'theme.css');
$vm_mainframe->addScript(VM_THEMEURL.'theme.js');
// Reset of VM defaults JS bits
define ("_MOOTOOLS_LOADED", "1");
define ("_SLIMBOX_LOADED", "1");
vmRequest::setVar("usefetchscript", 0, "session");
class rokCommonHTML extends vmCommonHTML {
function getRokboxImageLink($image_link, $text, $title='', $image_group='') {
if($image_group) {
$image_group = '('.$image_group.')';
}
$img = str_replace(JURI::base(), '', $image_link);
if ($img_size = @getimagesize($img)) $size = "[{$img_size[0]} {$img_size[1]}]";
else $size = "";
$link = rokCommonHTML::hyperLink($image_link, $text, '', $title, 'rel="rokbox'.$size.$image_group.'"');
return $link;
}
}
// End of Reset
class vmTheme extends vmTemplate {
function vmTheme() {
parent::vmTemplate();
// Removing this, since we're loading it already from our template
//vmCommonHTML::loadMooTools();
}
function vmBuildFullImageLink($product) {
global $VM_LANG;
$product_image = '';
$img_attributes= 'style="max-height: 100px; max-width: 100px"' . ' title="' . htmlspecialchars($product['product_name']) . '"';
/* Wrap the Image into an URL when applicable */
if (@$product["product_url"]) {
$product_image = "<a href=\"". $product["product_url"]."\" title=\"".$product['product_name']."\" target=\"_blank\">";
$product_image .= ps_product::image_tag($product['product_thumb_image'], $img_attributes, 0);
$product_image .= "</a>";
}
/* Show the Thumbnail with a Link to the full IMAGE */
else {
if(empty($product['product_full_image'])) {
$product_image = "<img src=\"".VM_THEMEURL.'images/'.NO_IMAGE."\" alt=\"".$product['product_name']."\" border=\"0\" />";
}
else {
// file_exists doesn't work on remote files,
// so returns false on remote files
// This should fix the "Long Page generation bug"
if(file_exists(IMAGEPATH.'product/'.$product['product_full_image'])) {
/* Get image width and height */
if($image_info = @getimagesize(IMAGEPATH.'product/'.$product['product_full_image'])) {
$width = $image_info[0] + 20;
$height = $image_info[1] + 20;
}
}
else {
$width = 640;
$height= 480;
}
if(stristr($product['product_full_image'], "http")) {
$imageurl = $product['product_full_image'];
}
else {
$imageurl = IMAGEURL.'product/'.rawurlencode($VM_LANG->convert($product['product_full_image']));
}
/* Build the "See Bigger Image" Link */
if(@$_REQUEST['output'] != "pdf" && $this->get_cfg('useLightBoxImages', 1)) {
$link = $imageurl;
$text = ps_product::image_tag($product['product_thumb_image'], $img_attributes, 0)."<br/>".$VM_LANG->_('PHPSHOP_FLYPAGE_ENLARGE_IMAGE');
//$product_image = vmCommonHTML::getLightboxImageLink($link, $text, $product['product_name'], 'product'.$product['product_id']);
$product_image = rokCommonHTML::getRokboxImageLink($link, $text, $product['product_name'], 'product'.$product['product_id']);
}
elseif(@$_REQUEST['output'] != "pdf") {
$link = $imageurl;
$text = ps_product::image_tag($product['product_thumb_image'], $img_attributes, 0)."<br/>".$VM_LANG->_('PHPSHOP_FLYPAGE_ENLARGE_IMAGE');
// vmPopupLink can be found in: htmlTools.class.php
$product_image = vmPopupLink($link, $text, $width, $height);
}
else {
$product_image = "<a href=\"$imageurl\" target=\"_blank\">"
. ps_product::image_tag($product['product_thumb_image'], $img_attributes, 0)
. "</a>";
}
}
}
return $product_image;
}
/**
* Builds a list of all additional images
*
* @param int $product_id
* @param array $images
* @return string
*/
function vmlistAdditionalImages($product_id, $images, $title='', $limit=1000) {
global $sess;
$html = '';
$i = 0;
foreach($images as $image) {
$thumbtag = ps_product::image_tag($image->file_name, 'class="browseProductImage"', 1, 'product', $image->file_image_thumb_width, $image->file_image_thumb_height);
$fulladdress = $sess->url('index2.php?page=shop.view_images&image_id='.$image->file_id.'&product_id='.$product_id.'&pop=1');
if($this->get_cfg('useLightBoxImages', 1)) {
//$html .= vmCommonHTML::getLightboxImageLink($image->file_url, $thumbtag, $title ? $title : $image->file_title, 'product'.$product_id);
$html .= rokCommonHTML::getRokboxImageLink($image->file_url, $thumbtag, $title ? $title : $image->file_title, 'product'.$product_id);
}
else {
$html .= vmPopupLink($fulladdress, $thumbtag, 640, 550);
}
$html .= ' ';
if(++$i > $limit) break;
}
return $html;
}
/**
* Builds the "more images" link
*
* @param array $images
*/
function vmMoreImagesLink($images) {
global $mosConfig_live_site, $VM_LANG, $sess;
/* Build the JavaScript Link */
$url = $sess->url("index2.php?page=shop.view_images&flypage="[email protected]$_REQUEST['flypage']."&product_id="[email protected]$_REQUEST['product_id']."&category_id="[email protected]$_REQUEST['category_id']."&pop=1");
$text = $VM_LANG->_('PHPSHOP_MORE_IMAGES').'('.count($images).')';
$image = vmCommonHTML::imageTag(VM_THEMEURL.'images/more_images.png', $text, '', '16', '16');
return vmPopupLink($url, $image.'<br />'.$text, 640, 550, '_blank', '', 'screenX=100,screenY=100');
}
// Your code here please...
}
?>
찾은 코드 샘플을 게시하고 "나를 위해이 일을하십시오"라고 묻는 것은 게으르다. 이 작품이 어떻게 작동하는지 알아내는 것은 당신에게 보람과 교육이 될 것입니다. 다른 사람들이 당신을 위해 일하기를 간청한다면 결코 좋은 코더가 될 수 없습니다. – TravisO
나는 개인적으로 어디서부터 시작해야할지 모른다. 나는이 일을하는 법을 알지 못하지만, 어쨌든 감사드립니다. – Chris