2017-02-14 4 views
0

ich versuche, wie Bild, um die Größe unterneue JImage: Die Bilddatei existiert nicht

<?php 
    $file = htmlspecialchars($product->image); 
    $image = new JImage($file); 
    $properties = JImage::getImageFileProperties($file); 
    $resizedImage = $image->resize(108, 108, true); 
    //definition of mime 
    $resizedImage->toFile(htmlspecialchars($product->image), $type); 
?> 
    <img src="<?php print $product->image ?>"/> 

aber eine Reihe 2 verursacht einen Fehler

0 Die Bilddatei existiert nicht.

Eine Datei ist vorhanden und Code

<img src="<?php print $product->image ?>"/> 

zeigt ein Bild (ohne Code zum Ändern der Größe oben).

Wenn ich versuche, wie dies

new JImage(JPATH_ROOT.'/components/com_jshopping/files/img_products/thumb_goods-11.jpg'); 

Weg zum Bild zu codieren diese Fehler nicht verursacht.

jedoch erscheint eine Warnmeldung unter

Warnung: imagejpeg (http://localhost/svark/components/com_jshopping/files/img_products/thumb_goods-11.jpg): failed to open stream: HTTP-Wrapper unterstützt keine beschreibbaren Verbindungen in C: \ xampp \ htdocs \ svark \ Bibliotheken \ joomla \ image \ image.php on line 985

ich Joomla 3.6.5 mit JoomShopping 4.15.1 verwenden.

Antwort

1

Sie benötigen einen absoluten Pfad zur Bearbeitung, Sie können http nicht verwenden.

Um einen absoluten Pfad zu verwenden, diese

new JImage(JPATH_ROOT.'/components/com_jshopping/files/img_products/thumb_goods-11.jpg'); 

TO

new JImage(JPATH_BASE.'/components/com_jshopping/files/img_products/thumb_goods-11.jpg'); 
0

Probieren Sie dies aus ändern:

// Set the path to the file 
$file = '/Absolute/Path/To/File'; 

// Instantiate our JImage object 
$image = new JImage($file); 

// Get the file's properties 
$properties = JImage::getImageFileProperties($file); 

// Declare the size of our new image 
$width = 100; 
$height = 100; 

// Resize the file as a new object 
$resizedImage = $image->resize($width, $height, true); 

// Determine the MIME of the original file to get the proper type for output 
$mime = $properties->mime; 

if ($mime == 'image/jpeg') 
{ 
    $type = IMAGETYPE_JPEG; 
} 
elseif ($mime = 'image/png') 
{ 
    $type = IMAGETYPE_PNG; 
} 
elseif ($mime = 'image/gif') 
{ 
    $type = IMAGETYPE_GIF; 
} 

// Store the resized image to a new file 
$resizedImage->toFile('/Absolute/Path/To/New/File', $type); 
Verwandte Themen