DropzoneJS thumbnailWidth and thumbHeight don't work - dropzone.js

Problem
I'm using dropzone to handle multiple image uploads. I want it to generate 280x280px thumbnails. Despite my best efforts, it keeps generating 100x100px thumbnails.
Code
Here is my code:
Dropzone.options.addPhotosForm = {
createImageThumbnails: true,
thumbnailWidth: "280",
thumbnailHeight: "280",
...
}
Here is my contact form:
<form action="{{ route('store_photo_path', [$rooms->slug]) }}"
method="POST" class="dropzone" id="addPhotosForm">
{{ csrf_field() }}
</form>
Here is my CSS:
.dropzone .dz-preview .dz-image {
width: 280px;
height: 280px;
}
I have tried with and without the quotes, with single and with double quotes. Nothing has worked so far.
Do you guys know what could be the problem?
Thanks!
I have read and tried these solutions:
quotes/no quotes,
xhrs,
any of these, and
jQuery.
Solution:
I finally realized what I was doing wrong. I create the thumbnails in my Photo.php file. Under the makeThumbail function, I had "->fit(100)" which forced the thumbnail to be a 100x100 image. After changing this to "->fit(280)", this fixed the problem.
Here is my code:
Code for solution
public function makeThumbnail()
{
Image::make($this->path)
->fit(280)
->save($this->thumbnail_path);
}

Besides modifying the size of the thumbnail as you are doing, you need to modify the .dz-image class in the CSS file accordingly.

Solution:
I finally realized what I was doing wrong. I create the thumbnails in my Photo.php file. Under the makeThumbail function, I had "->fit(100)" which forced the thumbnail to be a 100x100 image. After changing this to "->fit(280)", this fixed the problem.
Here is my code:
public function makeThumbnail()
{
Image::make($this->path)
->fit(280)
->save($this->thumbnail_path);
}

Related

How in vuetify to set size of carousel images

In my Laravel 5.6/"vue": "^2.5.7/"vuetify": “^1.0.8” application I use carousel of
images ( https://vuetifyjs.com/en/components/carousels#introduction )
it works but if there are uploaded images of different size the images are partly cut and view is broken.
I tried to make like :
<v-carousel>
<v-carousel-item v-for="(nextArtistImage,i) in artistImagesList" :src="nextArtistImage.image_url" :key="nextArtistImage.id"
:alt="nextArtistImage.image_url" style="width: 200px;height:auto;">
<div class="carousel_image_title">{{ nl2br(concatStr(nextArtistImage.description, 100)) }}</div>
</v-carousel-item>
</v-carousel>
But my attempts to change style did not alter anything...
If there is a valid way ?
Thanks!
Try...
<v-carousel>
<v-carousel-item v-for="(nextArtistImage,i) in artistImagesList" :key="nextArtistImage.id">
<img :src="nextArtistImage.image_url" style="width:200px;height:auto;" :alt="nextArtistImage.image_url"/>
</v-carousel-item>
</v-carousel>
The above html takes advantage of the default slot for the v-carousel-item.
<v-carousel height="auto">
<v-carousel-item></v-carousel-item>
</v-carousel>
enter link description here
Based on Vuetify Documentation
As I saw images are set as background pictures, for <div class="v-image__image--cover"></div>. They are not rendering on DOM as images (for example: <img src="image_src" />). So if you want to change image view, you have to override css properties of that div, for example background properties (background-position, background-size ...).
I am not sure it is a valid way or not, but if you want to change item's height you have to override carousel's height (<v-carousel>), because the height of <v-carousel-item> determined by height of carousel itself, or you have to override whole structure of carousel (change positions and some other css properties).
But there is one issue, I guess you want to render pictures of different original heights at one height, so that it does not turn off the view. This is a common problem for front-end developers. By the way, one of the best way to solve this problem is the structure you are trying to override.
The code below, shows the entire image within the carousel. Set the height of the v-carousel (300 in this example) and set that same value for the v-img max-height. If there are images that that wide but short, then limits to the width should also be added.
<v-carousel cycle v-model="model" height="300">
<v-carousel-item
v-for="(item, i) in items"
:key="i"
>
<v-img :src="item.src" contain max-height="300"></v-img>
</v-carousel-item>
</v-carousel>
Where items is defined as:
<script>
export default {
data() {
return {
items: [
{ src: require('#/assets/photo1.jpg') },
{ src: require('#/assets/photo2.jpg') },
],
};
},
};
</script>
#peter.edwards just a tiny mistake on your code:
<img src="nextArtistImage.image_url" style="width:200px;height:auto;" :alt="nextArtistImage.image_url"/>
Source of image cannot be loaded because is a string so the correct form should be <img :src="nextArtistImage.image_url" :alt="nextArtistImage.image_url"/> so the final form will be
<v-carousel>
<v-carousel-item
v-for="(itemnextArtistImagei) in artistImagesList"
:key="i"
><img :src="nextArtistImage.image_url" :alt="nextArtistImage.image_url"/>
</v-carousel-item>
</v-carousel>

check in blade view if image is loaded or 404

Is there a way to check in a blade view if an image is really there or not?
I need to show results from a search box.
The results are many boxes with infos and a picture for each box.
The point is in my DB I store links to images that are on remote servers and also name of images that are stored locally.
So what I am doing is check if the file exists locally and if so use it and if not look on the remote server (if the picture data is not NULL it's either there or in a remote server).
I was trying to check if file exists using curl and it works but for big collections it takes too much time to finally spit the data to the view (every link has to be checked).
So what I want to do, if possible, is check directly in the blade view if the picture is not broken (404) and if so replace with an "image-not-found.png" I store locally. How can I do that?
I usually handle this with JavaScript using the img tag's onerror event. Typically I add a few more bells and whistles to the solution but this is it in a nutshell.
Plan JavaScript
function loadNextImage(id,uri){
document.getElementById(id).src = uri;
}
Plain HTML
<img src="http://local/image.jpg"
onerror="loadNextImage('image1', 'http://remote/imae.jpg'));"
id='image1' />
VueJS and Webpack
<template>
<img :src="local_url" #error="imgOnError()" ref="image"/>
</template>
<script>
export default{
name: 'Thumbnail',
props: {
local_url: String,
remote_url: String
},
methods: {
imgOnError: function (e) {
this.$refs.image.src = this.remote_url
}
}
}
</script>
You can use the func "file_get_contents" inside a try-catch block. I know i not the best way, but i could work for you.
Tray this (no the best way):
<?php
try{
$img = 'myproject.dev/image.jpg';
$test_img = file_get_contents($img);
echo "<img src='{$img}'>";
}catch(Exception $e){
echo "<img src='img/no-img.jpg'>";
}
?>

Merge Logo Into Simple QRCode (Laravel 5)

I'm using https://www.simplesoftware.io/docs/simple-qrcode to generate QR code with laravel 5. I want to add a logo at the centre of the qr code since it's doable (according to this plugin) however part of the output was something like this:
j�W�X�"(�#��E 4=��X w����M�X�"(�#��EG��=5y��'��wX���I�C��E P,�bu� {?��ݻ�����Ò��"(�#��E P,��WX-�Vm\VWF��qb��'B���#�X�"(�#����T������L��M��꽾�Q�m�#- r�h�����ly"#{��������bQe_��Z]]��ko����G7EDT�i4TH�,}����t��������ŷ�n�������Q�啵�����R�F�m� �(��|x�����ny%���������UQU�5)U˾+���lUX���k��L=��O��kyemv�X��h�D�L$s>� L����L�$�9������$��(�\a�幂 ��ů�U�qK%��D�P��N��D3���$K��ʣ��#�Օ���i2s����nT��a�I㲎��7+)AG�H�>�;�$��KMT���J�<|����p��;�K7��!��<.*'N���7��>�%�ɮs:AMLD-����3J�䃭?�
Here is my code:
{!! QrCode::format('png')->merge('https://www.seeklogo.net/wp-content/uploads/2016/09/facebook-icon-preview-1.png', .3, true)->size(200)->generate('http://www.simplesoftware.io'); !!}
Anyone experience with this kindly help me out, your help is appreciated! :)
Thank you.
You are seeing the raw output of a PNG image. You will need to base64 encode the image and then place it within an img tag like this:
<img src="data:image/png;base64, {!! base64_encode(QrCode::format('png')->merge('https://www.seeklogo.net/wp-content/uploads/2016/09/facebook-icon-preview-1.png', .3, true)->size(200)->generate('http://www.simplesoftware.io');) !!} ">
You should not return file by blade. In your controller you should have something like:
$response = Response::make($file);
$response->header('Content-Type', "image/png");
return $response;

Symfony2 - Checking if a file exists in Twig

Is there a way to check if the file exists in Twig for an image uploaded in a newly created post?
The way I have my post setup is if an image is not uploaded the Twig template will show an empty box with the proportions of where the image should be, but it's a blank box that's awkward to look at.
Question, is if there is a specific command to use with an if statement to check if a file exists if so, display the image code if not do not display the image code.
Image code: (this is the code I want to hide if no image exists to get rid of the empty box)
<div class="entry-thumbnail">
<img width="230" height="172" src="{{ asset(['images/', post.image]|join) }}" class="" alt=""/>
</div>
you could write a twig extension and use some code like this:
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Finder\Finder;
$this->fs=new Filesystem();
if (!$this->fs->exists($directory)) {
$this->logger->info("there is no ".$directory." ...");
} else {
$this->logger->info("Directory ".$directory." already exists.");
}
but i would rather use javascripz like
in your img tag :
<img ... onError="this.src='imagefound.gif';" />
update:
The image Tag has an onError-Handler that triggers when the image in the src attribute is not found. So instead of using this simple inline syntax you could do the same like :
pseudo jquery code:
$(document).on('error','img',function(){
$(this).attr("src","../path/to/placeholerImage.png");
});

jcrop is not working on internet explorer 8

I am using Jcrop to crop images in my web-application. It works great on all browsers (IE9, FF, Chrome, Safari) except IE8. Specifically, 8.7.6 which ships with Windows 7.
I am using Jcrop v 0.9.9.
In Firefox where it works.I see a structure a DOM like
img id... "style="display:none"
div class="jcrop-holder" ......
.........................
img ........
div
Where as in IE 8.7.6, I see the DOM like
img id... "style="display:none"
----Blank-------
Basically, the jcrop-holder is not being injected into the DOM while original image is hidden just like other browsers.
Can you pls. shed some light on this? and If you know any workarounds for IE.
Your help is appreciated.
Javascript Code to attach jcrop to target image
function attachJcropToModal()
{
jQuery(function($)
{
$('#jcrop_target').Jcrop(
{
aspectRatio: '<%=defaultAspectRatioValue%>',
minSize: [0,0],
onChange: updateCoords,
onSelect: updateCoords
},
function ()
{
jcrop_api = this;
}
);
});
}
function updateCoords(c)
{
$('#w').val(Math.round(c.w*adjFactor));
$('#h').val(Math.round(c.h*adjFactor));
$('#x1').val(Math.round(c.x*adjFactor));
$('#y1').val(Math.round(c.y*adjFactor));
}
Html image display code
<div class="cropperContainer">
<table>
<tbody><tr>
<td class="main">
<img id="jcrop_target" src="<%=imgSourceURL%>"<%=overriddenImageWidthAttr%> alt="" />
</td>
</tr>
</tbody></table>
</div>
Your code looks good, just one thing! You shouldn't use '' around the aspectRatio decimal value.
Jcrop Demo works on IE8, right?
Maybe you should give Cropzoom a try. I used this in a commercial project and after some tweaks it works great for us in IE7+, FF and Safari, etc...

Resources