Hey I just switched back to Journal which in my opinion, as a real world store owner not a developer, is probably the best theme out there for opencart.
We had the webp image issue but added some code from a comment in this extension:
https://www.opencart.com/index.php?rout ... n_id=38025
<file path="catalog/model/journal3/image.php">
<operation>
<search><![CDATA[return $this->model_tool_image->resize($filename, $width, $height, $resize_type);]]></search>
<add position="before"><![CDATA[$resize_type = '';]]></add>
</operation>
</file>
Fixed any broken image issue. And yes, you should use webp. If someone is using a browser that doesn't support it, they are probably 80 years old and don't shop online anyway.
soulliving wrote: ↑Sun Jan 02, 2022 4:48 am
Hello!
Webp pictures is working everywhere else on the site, but I can`t find a module or thread on how to get it to work with insterted images (uploaded to server) in product description. We use up to 20 images sometimes and would be nice to get them in webp format too.
Any experience with this?
Running Opencart 3.0.3.8 with Journal 3 theme (yes I know the feelings about the theme).
Image.php in ocartdata is this:
Code: Select all
<?php
class ModelToolImage extends Model {
public function resize($filename, $width, $height, $type = '') {
if (!is_file(DIR_IMAGE . $filename) || substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != str_replace('\\', '/', DIR_IMAGE)) {
return;
}
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$image_old = $filename;
$image_new = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int)$width . 'x' . (int)$height . $type . '.' . $extension;
if (!is_file(DIR_IMAGE . $image_new) || (filemtime(DIR_IMAGE . $image_old) > filemtime(DIR_IMAGE . $image_new))) {
list($width_orig, $height_orig, $image_type) = getimagesize(DIR_IMAGE . $image_old);
if (!in_array($image_type, array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF))) {
return DIR_IMAGE . $image_old;
}
$path = '';
$directories = explode('/', dirname($image_new));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!is_dir(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
if ($width_orig != $width || $height_orig != $height) {
$image = new Image(DIR_IMAGE . $image_old);
$image->resize($width, $height, $type);
$image->save(DIR_IMAGE . $image_new);
if (defined('JOURNAL3_ACTIVE')) {
if ($this->journal3->settings->get('performanceCompressImagesStatus')) {
\Journal3\Utils\Img::optimise(DIR_IMAGE . $image_new);
}
}
} else {
copy(DIR_IMAGE . $image_old, DIR_IMAGE . $image_new);
if (defined('JOURNAL3_ACTIVE')) {
if ($this->journal3->settings->get('performanceCompressImagesStatus')) {
\Journal3\Utils\Img::optimise(DIR_IMAGE . $image_new);
}
}
}
}
if (defined('JOURNAL3_ACTIVE')) {
if ($this->journal3->settings->get('performanceCompressImagesStatus')) {
$image_new = \Journal3\Utils\Img::cwebp($image_new);
}
}
$image_new = str_replace(' ', '%20', $image_new); // fix bug when attach image on email (gmail.com). it is automatic changing space " " to +
if (defined('JOURNAL3_STATIC_URL')) {
return JOURNAL3_STATIC_URL . 'image/' . $image_new;
}
if ($this->request->server['HTTPS']) {
return $this->config->get('config_ssl') . 'image/' . $image_new;
} else {
return $this->config->get('config_url') . 'image/' . $image_new;
}
}
}
Image.php in /catalog/model/tool/ is
Code: Select all
<?php
class ModelToolImage extends Model {
public function resize($filename, $width, $height) {
if (!is_file(DIR_IMAGE . $filename) || substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != str_replace('\\', '/', DIR_IMAGE)) {
return;
}
$extension = pathinfo($filename, PATHINFO_EXTENSION);
$image_old = $filename;
$image_new = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int)$width . 'x' . (int)$height . '.' . $extension;
if (!is_file(DIR_IMAGE . $image_new) || (filemtime(DIR_IMAGE . $image_old) > filemtime(DIR_IMAGE . $image_new))) {
list($width_orig, $height_orig, $image_type) = getimagesize(DIR_IMAGE . $image_old);
if (!in_array($image_type, array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF))) {
return DIR_IMAGE . $image_old;
}
$path = '';
$directories = explode('/', dirname($image_new));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!is_dir(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
if ($width_orig != $width || $height_orig != $height) {
$image = new Image(DIR_IMAGE . $image_old);
$image->resize($width, $height);
$image->save(DIR_IMAGE . $image_new);
} else {
copy(DIR_IMAGE . $image_old, DIR_IMAGE . $image_new);
}
}
$image_new = str_replace(' ', '%20', $image_new); // fix bug when attach image on email (gmail.com). it is automatic changing space " " to +
if ($this->request->server['HTTPS']) {
return $this->config->get('config_ssl') . 'image/' . $image_new;
} else {
return $this->config->get('config_url') . 'image/' . $image_new;
}
}
}
Hope there is someone that has fixed something like this before
Self Taught Opencart User & Developer Since 2010.