I have created a child theme based on Storefront Woocommerce 3.3. Without adding support image. 3500 images have been uploaded and only the original size exist
I added support theme in function and tried to create the thumbs via plugin
function iconic_modify_theme_support() {
$theme_support = get_theme_support( 'woocommerce' );
$theme_support = is_array( $theme_support ) ? $theme_support[0] : array();
$theme_support['single_image_width'] = 320;
$theme_support['thumbnail_image_width'] = 150;
$theme_support['gallery_thumbnail_image_width'] = 50;
remove_theme_support( 'woocommerce' );
add_theme_support( 'woocommerce', $theme_support );
}
add_action( 'after_setup_theme', 'iconic_modify_theme_support', 10 );
when I use force thumbnail regenarate for an image produce
in database wp_option
woocommerce_thumbnail_cropping, uncropped,yes
thumbnail_crop,1, yes
100x100, 102x300, 150x150, 300x883 shouldn't 17x150 be created?
the 100x100 have been created because of wordpress (and not woocommerce) setting? is it possible to cancel that?
Front page, archive page, single product and in admin's dashboard products list load (src) the file of full image (for example 700x400) the image will be displayed in lower dimensions ( 150x100 for example) but it will load the big file image.
Server in upload folder doesn't have same image in different sizes ( image.jpg , image150x100.jpg image50x30.jpg )
I dont have anything in function.php about the size of image
in Single product page image is retrieved from woocommerce
do_action( 'woocommerce_before_single_product_summary' );
in Archive product I get the image
if( has_post_thumbnail() ){
the_post_thumbnail( 'shop_catalog', array( 'class' => 'visible_photo scale-with-grid' ) );
} elseif ( wc_placeholder_img_src() ) {
echo wc_placeholder_img( 'shop_catalog' );
}
Is it possible to use gallery_thumbnail in admin's product list ?
In Settings -> Media -> Thumbnail size uncheck "Crop thumbnail to exact dimensions (normally thumbnails are proportional)".
Related
Need some help with images.
As the topic says, I want to create an image with live updating text on it.
This is mainly used by game servers and players to show off their stats and info. Server-wise, to show if the server is online and how many players are online and such.
I haven no idea how to do it and figured this would be the best place to find out. Since I don't have any idea what this is even called, i did not know what to search for.
Thanx in advance.
This is an html+css+ajax solution. Make the image an html element's background image. Let's use a div. Then position the text in the div. Use ajax to update the text. The image will remain the same while the text can be updated.
Was possible with the use of API. Created an API of the database I want to use, connected to the database and everything worked!
After using $API_GET to get the data, I set it into an array-format.
Used PHP for everything.
From there on I used imagecreatefrompng, obviously to select an image.
Set a few colors using imagecolorallocate and from there on it was purely adding the text on the image as to where I want them using imagettftext.
Creating an image, with live updating stats on it.
But we still have to tell the browser to load it as an image and not a page with an image on it, so therefor...
header( "Content-type: image/png" );
And imagesetthickness to 5, followed by imagepng and imagedestroy.
Code Extracts:
$API_GET = file_get_contents("API URL");
$API_GET = json_decode($API_GET);
$API = array();
foreach ($API_GET as $key => $value) {
$API[$key] = $value;
}
if (file_exists($imagefile)) {
$bg_img = imagecreatefrompng ( "IMAGE URL");
$color_red = imagecolorallocate( $bg_img, 250, 0, 0 );
imagettftext($bg_img, 20, 0, 19, 36, $color_red, 'FONT URL.tff',"Text On Image");
imagesetthickness ( $my_img, 5 );
header( "Content-type: image/png" );
imagepng( $my_img );
imagedestroy( $my_img );
} else {
echo 'Image does not exist.';
}
That is the basic structure of the code.
Thank You for your reply to the question.
I am trying to remove the ability to click on an image in woocommerce's product featured images, so that you can no longer click on the image and make it bigger.
Not much skills with css so simple explanations are appreciated.
I have the product-image.php open and I know how to enter custom code into my theme.
Anyone?
Change this line inthe product-image.php
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '%s', $image_link, $image_title, $image ), $post->ID );
to
echo apply_filters( 'woocommerce_single_product_image_html', sprintf( '%s', $image ), $post->ID );
and in the product-thumbnails.php file, change
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '%s', $image_link, $image_class, $image_title, $image ), $attachment_id, $post->ID, $image_class );
to
echo apply_filters( 'woocommerce_single_product_image_thumbnail_html', sprintf( '<a title="%s">%s</a>', $image_title, $image ), $attachment_id, $post->ID, $image_class );
Doing the above should remove the ability to click on the image and make it bigger.
works perfectly however I'm facing one issue because of it. I set up my page so that when I click a thumbnail it replaces the product image. When I apply your rule to make the product image unclickable, then the other js doesnt work anymore. Do you have any idea how I could make both work together? The jquery Im using is
(function($){
$(document).ready(function(){
$('.thumbnails a.zoom').click(function(event){
event.preventDefault();
var thumb_url = $(this).find('img').attr('src');
$('.woocommerce-main-image img').attr('src', thumb_url );
});
});
})(jQuery);
Try this
.woocommerce-product-gallery__image {
pointer-events: none;
It works perfectly for me.
Check if your theme has a custom CSS section and just paste it there.
First of all, if you want to replace single-product.php template you have to create a new one in you own theme folder.
Example: wp-content/themes/woocommerce/single-product.php
<?php
global $product;
echo $product->get_image();
?>
Will output only img tag without link and any div's.
This might be helpful https://docs.woocommerce.com/wc-apidocs/source-class-WC_Block_Featured_Product.html#156-175
I was looking for how to disable the zoom and lightbox on product images and the following code (inserted on functions.php) helped:
add_action( 'after_setup_theme', 'remove_pgz_theme_support', 100 );
function remove_pgz_theme_support() {
remove_theme_support( 'wc-product-gallery-zoom' );
remove_theme_support( 'wc-product-gallery-lightbox' );
}
This had, however, the side effect of still allowing users to click on the image, sending them to the direct link of the file. On the OceanWP theme I found this to work (insert it on your css):
img.wp-post-image {
pointer-events:none !important;
This will work for the featured image, but if you have other images in the same product gallery, those ones will still be clickable. To disable the click on those too, insert this extra code on your css:
div.woocommerce-product-gallery__image.flex-active-slide {
pointer-events:none !important;
Hope it helps you!
After exporting, changing some details and then importing a large number of products into Magento, I noticed all the images are no longer set. The images still exist in the media gallery for each product, but they are not set as the base image.
I've seen that in some cases, you need to copy images over to a /media/import/ folder, but is it possible to change the import file so that I can keep the images where they are?
Right now, all the images appear to be in a folder: /media/catalog/product/
Any help would be very appreciated.
Additionally, if it were possible to run a script that sets all product's base image to the first image in its gallery, that would work just as well. Thanks!
Let's say that you have load the products and you are ready to make a change and save them. With this code:
if (file_exists($imagePath)) {//New image file
//Load your media table
$mediaApi = Mage::getModel("catalog/product_attribute_media_api");
try {
//Now you have all the images available for your product
//if you previously have assign anything
$items = $mediaApi->items($product->getId());
//loop them
foreach ($items as $item) {
//With that line you can remove them if you want
echo ($mediaApi->remove($product->getId(), $item['file']));
}
} catch (Exception $exception) {
var_dump($exception);
die('Exception Thrown');
}
$cache = Mage::getSingleton('core/cache');
$cache->flush();
//You need that line
$product->setMediaGallery(array('images' => array(), 'values' => array()));
//That line assigns your new image.As base,thumbail and image.
//Use it in the loop if you want to reassign an existing image.
$product->addImageToMediaGallery($imagePath, array('thumbnail', 'small_image', 'image'), false, false);
I hope that helps you
Cheers!
I installed the plugin http://wordpress.org/plugins/automatic-featured-image-posts/ but I am having a problemm, because the plugin doesn't remove the original image from the post content after creating the featured image. (and therefore when I don't add the featured image there appear 2 images on the post)
I tried adding this to the auto-featured-image.php
add_action('publish_post', 'eliminaroriginal');
and then
function eliminaroriginal(){ //update the post without image
$post_parent_id = $post->post_parent === 0 ? $post->ID :
$post->post_parent; $contenido = preg_replace("/[caption
.+?[/caption]|\< [img][^>][.]*>/i", "", $post->post_content,
1); $mipost = array(); $mipost['ID'] = $post_parent_id;
$mipost['post_content'] = $contenido; wp_update_post( $mipost );
}
but it didn't have any result.
Please help me, I don't know what should I do.
Thank you before hand!
i am trying to display product gallery images in my custom cms home page. If i use the code from media.phtml to display the gallery images, it does not work. I found this piece of code and it worked.
<div id="thumbs" class = "thumbs-home">
<?php
$obj = new Mage_Catalog_Block_Product_View_Media();
$_product1 = new Mage_Catalog_Model_Product();
// Load all product information of a particular product
$Products_one = Mage::getModel('catalog/product')->load($productId);
// Use your Product Id instead of $id
$countt = count($Products_one->getMediaGalleryImages());
if($countt>0){
foreach ($Products_one->getMediaGalleryImages() as $_image)
{
// For the Original Image
$thumb_img = "<img src=".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).str_replace(Mage::getBaseUrl('media'),"",$_image->url)." alt=''width='60' height='60' />";
echo "<a href='".Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).str_replace(Mage::getBaseUrl('media'),"",$_image->url)."'rel='lightbox[gallery]'>".$thumb_img."</a>";
//For gallery Image
//$resizeimage = $obj->helper('catalog/image')->init($_product, 'thumbnail', $_image->getFile())->backgroundColor(242,242,243)->resize(400,300);
//echo "<img src=".$resizeimage."alt='' />";
}
}
?>
This gets the actual images and gets resized by the width and height attributes. But i want to resize the image through magento. The last piece of code $resizeimage is not working for some reason. How can i make this work? The problem is that i am using a lightbox to display the gallery images which displays the actual high resolution images that are too large. The light box takes in width and height of image provided and i am not able to figure out as to how i set a standard dimensions for the light box. So the only other option is the have the images resized by magento before passing them to the lightbox. Thanks.
You just need to call proper object, instead of $obj->helper you should use Mage::helper, so your call should look like this:
print Mage::helper('catalog/image')
->init($product, 'thumbnail', $image->getFile())
->backgroundColor(255,255,255)
->resize(100,100);
And that's it! :)