new JImage: The image file does not exist - joomla

I trying to resize image like below
<?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 ?>"/>
but a row 2 causes an error
0 The image file does not exist.
A file is exists and code
<img src="<?php print $product->image ?>"/>
shows an image(without code for resizing above).
If I trying to hardcode path to image like this
new JImage(JPATH_ROOT.'/components/com_jshopping/files/img_products/thumb_goods-11.jpg');
this does not cause errors.
However, a warning message appears below
Warning:
imagejpeg(http://localhost/svark/components/com_jshopping/files/img_products/thumb_goods-11.jpg):
failed to open stream: HTTP wrapper does not support writeable
connections in C:\xampp\htdocs\svark\libraries\joomla\image\image.php
on line 985
I'm using Joomla 3.6.5 with JoomShopping 4.15.1.

You need an absolute path for editing purpose, you cannot use http.
To use an absolute path, change this
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');

Related

Rename a base64 encoded image on download

I have the following code to display an image - without going into details about why I am not just using the image name.
<?php
$data = base64_encode(file_get_contents('example.png'));
$info = getimagesize('example.png');
$image = sprintf('data:%s;base64,%s', $info['mime'], $data);
?>
<img src="<?php echo $image; ?>" download='final-image.png' />
It works as expected displaying the image.
However when someone right-clicks the image, in FireFox it wants to save it as (scriptname).png and Chrome wants to save it as download.png.
I can't use header() as headers are already being sent.
Is there any way to force a filename that works across browsers?

File does not exist maatwebsite/excel laravel export from view

Tried to export an excel file through a Laravel blade but the issue exists when trying to add an image that is from external link not the same server (it's from google storage) the image is accessible through browser
The error is:
PhpOffice\PhpSpreadsheet\Writer\Exception File URL does not exist
Also, tried to get base64 and also didn't work
$type = pathinfo($url, PATHINFO_EXTENSION);
$data = file_get_contents($url);
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
didn't work <img src='{{$url}}' style="height: 20px;" height="100px">
didn't work <img src='{{$base64}}' style="height: 20px;" height="100px">
I solved it by temporally download the image into the server and use the path to the image on the server.

Qrcode in laravel

i want to make qrcode, in there i can make it but i have something trouble when i want to change the format of qrcode to png file. but its only show symbol
here my view :
<?php echo QrCode::size(265)->generate($row->id) ?>
this qrcode i use :
"simplesoftwareio/simple-qrcode": "~1"
here my referance : https://www.simplesoftware.io/docs/simple-qrcode
can anyone help me ? or can someone give me solution ?
before i change format to png :
and this after i change it :
There are more simple example available as well.
<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(100)->generate('QrCode as PNG image!')) !!} ">
If you are formatting it as png file format, you need to include it with a <img> tag.
Taken from the documentation
//Inside of a blade template.
<img src="{!!$message->embedData(QrCode::format('png')->generate('Embed me into an e-mail!'), 'QrCode.png', 'image/png')!!}">
You can also do this:
$png = QrCode::format('png')->size(512)->generate(1);
$png = base64_encode($png);
echo "<img src='data:image/png;base64," . $png . "'>";
In controller
$path = getenv('IMAGE_URL')."/img/logo.png";
$png = QrCode::format('png')->merge($path, .17, true)->size(300)->errorCorrection('H')->generate($data);
$png = base64_encode($png);
In blade file
<img src='data:image/png;base64,{{$png}}'>
I came to this page because I needed to create a PNG file to send inline in an email in laravel8.
I used the examples above in order to create the QR code as a png which worked brilliantly. I used the following code:
<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->size(100)->generate('QrCode as PNG image!')) !!}" />
However a number of email services (including Gmail) do not display images that use inlined base64 as above. Instead, they require you to add the base64 image as an attachment to the email and then reference that attachment in the img src.
Thankfully laravel (I'm using laravel8) has a really cool function that does this for you, so my code ended up looking like this (which worked):
<?php
$qrCodeAsPng = QrCode::format('png')->size(500)->generate("my text for the QR code");
?>
<img src="{{ $message->embedData($qrCodeAsPng, 'nameForAttachment.png') }}" />
The $message variable is one that is in every blade that is being sent as an email in laravel. In my case I did not want to create an actual image on the server, but if you wanted to use an image that you had stored you would use $message->embed().

Slimbox integration with Virtuemart 2, Joomla 2.5

I am trying to replace the default lightbox 'modal' to 'slimbox', because 'modal' doesn't have the navigation arrows.
Demo of slimbox with navigations
Demo of modal without navigations
I am using these paths to modify the calling of slimbox
[templatename]/html/com_virtuemart/productdetails/default.php
components/com_virtuemart/productdetails/default.php
Joomla v2.5
Virtuemart 2.0.6
Slimbox2
The following is my attempt:
//Enable Slimbox2 plugin
$front = JURI::root(true).'/components/com_virtuemart/assets/';
$document = JFactory::getDocument();
$document->addStyleSheet($front.'js/slimbox/slimbox.css');
$document->addScript($front.'js/slimbox/slimbox2.js');
$js = 'jQuery(document).ready(function($) { $("a.lightbox").slimbox(); });';
$document->addScriptDeclaration($js);
//output thumbnail
echo $this->product->images[0]->displayMediaThumb('class="product-image"',true,'class="lightbox" rel="lightbox"'.$this->product->virtuemart_product_id.'"',true,true);
//unset first image not to be show amont additional ones
unset ($this->product->images[0]);
?>
But its still not working I wondered what's wrong?
[Reference][3]
You aren't applying the slimbox class to the image reference, your applying it to the container of the image aren't you? You need to deal with the image file url directly in my opinion.
// get the file_url of the first image
$imgPath = $this->product->images[0]->file_url;
// output the image
<a class="slimbox" href="<?php echo $imgPath; ?>">
<img src="<?php echo $imgPath; ?>" alt="" />
</a>

Change in APC for Magento stops SimplePie from working

We have been using SimplePie on our Magento install to pull our blog posts into our home page without issue for several months now. Due to some other issues with Magento, we had our web host turn off opcode in APC. Once we did that, the next hourly update of SimplePie stopped the loading of the home page and returns the following error in Apache:
[Wed Jan 18 09:59:57 2012] [error] PHP Fatal error: Class 'Zend_Log' not found in {server root}/lib/SimplePie/simplepie.inc on line 738
I am at a bit of a loss on what is happening and what to do to fix it. SimplePie is delivered as a banner/widget so if I put it on a different category page I get the same results. (Page stops at SimplePie command) I was hoping it would be something simple like the change is forcing the old chached RSS to remain and can not be modified but I am not sure.
Any help would be very appreciated!
The code for SimplePie is unaltered and is version 1.2.1. I have a page /app/design/frontend/default/default/template/page/html/blog.phtml which has the following code.
<div class="col-narrow right sidebar-blog">
<h2>Our Gardening Blog</h2>
<?php
// Make sure SimplePie is included. You may need to change this to match the location of
require_once('lib/SimplePie/simplepie.inc');
// We'll process this feed with all of the default options.
$feed = new SimplePie();
// Set which feed to process.
$feed->set_feed_url('http://blog.americanmeadows.com/feed/');
// Run SimplePie.
$feed->init();
// This makes sure that the content is sent to the browser as text/html and the UTF-8
$feed->handle_content_type();
/*
Here, we'll loop through all of the items in the feed, and $item represents the
current item in the loop.
*/
foreach ($feed->get_items(0,2) as $rss_item):
?>
<div class="article-teaser">
<p><span><?php echo $rss_item->get_date('F j, Y'); ?></span></p>
<h2 class="article-title"><?php echo $rss_item->get_title(); ?></h2>
<?php if ($rss_item->get_item_tags('', 'thumbnail')) {$thumbnail = $rss_item->get_item_tags('', 'thumbnail'); echo "<img src='" . $thumbnail[0]['data'] . "'>"; } ?>
<p><?php echo $rss_item->get_description(); ?> <a class="more" href="<?php echo $rss_item->get_permalink(); ?>" target="_blank">Continue Reading</a></p>
</div>
<?php endforeach; ?>
</div>
I then have a banner which calls only the following
{{block type="page/html" template="page/html/blog.phtml"}}
I include that banner in the left column widget on our home page to have it display.
The lines in SimplePie is throwing the error is
function SimplePie($feed_url = null, $cache_location = null, $cache_duration = null)
{
// Other objects, instances created here so we can set options on them
$this->sanitize =& new SimplePie_Sanitize; /* Error is thrown here */
// Set options if they're passed to the constructor
if ($cache_location !== null)
{
$this->set_cache_location($cache_location);
}
I think that is what you need but am happy to post more.
My only thought here is that somewhere something is setting Zend_Log as an error logger. Check for set_error_handler() in your code and see if that's being registered anywhere. (You could double check that by causing an error yourself with trigger_error() and seeing what happens.)
As for why the error is occurring, I'd hazard a guess at that being because you're using 1.2.1 with PHP 4, which will give E_DEPRECATED errors when assigning new by reference (such as on that line).

Resources