In a laravel based application we generate several chart with Jpgraph. Those charts are returned with all the correct headers. Like this:
$response = Response::make($img);
$response->header('Content-Type', 'image/png');
$response->header('Content-Disposition', 'inline');
return $response;
Whereby $img is the result of the Stroke function from jpgraph. Since stroke returns an image stream to the browser, I capture this with ob_get_contents to be able to use it in Response::make
Anyway. This renders the charts perfectly in any and all situation, excep with Dompdf.
The error I get is Image type unknown.
I have added a .png extension to the url but it doesn't work.
So far I've found nothing that's even close to a solution.
The problem proved to be something completely different
There was an issue where the Dompdf call to the image did not have the same session and therefore was not allowed to access the image
Thanks to everyone who commented
Related
I created lots of D3 chart in the application .
But right now my requirement is to save D3 chart in any format like png/gif or pdf.
I searched a lot and every one say we can use canvas for that.
Can anyone give any example or link for that...
Conceptually I am clear about that like
Use the canvg JavaScript library to render the SVG image using Canvas: https://github.com/gabelerner/canvg
Capture a data URI encoded as a JPG (or PNG) from the Canvas, according to these instructions: Capture HTML Canvas as gif/jpg/png/pdf?
What I want actually if any one have implemented, then could you please share the code.
After searching many resources and trying many things, I found SaveSvgAsPng
on GitHub.
It's very easy to implement and to use with resources available on README page on the same link.
Steps
Add Javascript library to your project.
Write a function with saveSvgAsPng call, include other options as required.
Example usage
saveSvgAsPng(document.getElementsByTagName("svg")[0], "plot.png");
Example function using d3.js
// I have button in html with id="download"
d3.select("#download")
.on('click', function(){
// Get the d3js SVG element and save using saveSvgAsPng.js
saveSvgAsPng(document.getElementsByTagName("svg")[0], "plot.png", {scale: 2, backgroundColor: "#FFFFFF"});
})
For this example, my plots are small for a web page so increased size to double for download and rather than transparent background as default I changed to white.
SaveSvgAsPng worked for me too. But if you want it to work in IE, you need to include "canvg" and pass it as parameter as below:
function saveAsImage(name, id) {
var svg = $('#'+id).find('svg')[0];
saveSvgAsPng(svg, name + '.png', { canvg: canvg, backgroundColor: 'white'});
}
"backgroundColor" parameter is also useful when your graphs need to be saved with a background.
I'm trying to smooth an scaled image loaded from another website. The image is not animated.
It works well if I use a local image. but it seems not work with images loaded from remote server.
Here is the snippet:
...
//_loader.load(new URLRequest(http://img.example.com/remote.jpg));
_loader.load(new URLRequest("../assets/local.jpg"));
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
...
protected function completeHandler(event:Event):void
{
var image:Bitmap = Bitmap(event.target.content);
image.smoothing = true;
image.pixelSnapping = "never";
}
As tested, when I load local.jpg, it works perfect. But when I load remote.jpg from the server, the smoothing param didn't work.
Anyone knows why?
I searched everywhere, but no one has the same problem. I'm not using Flash Professional, it's a pure ActionScript Project built in Flash Builder. And the image is not animating. So wired...
Because you are pulling an image from a remote server you need to set a cross domain policy xml file on the web server where the image is held.
Without this you can't alter bitmaps at a sub pixel level.
Example of:
http://www.senocular.com/pub/adobe/crossdomain/policyfiles.html
More details
http://www.adobe.com/devnet/articles/crossdomain_policy_file_spec.edu.html
I searched day by day, and finally find the answer:
_loader.load( new URLRequest("http:…." , new LoaderContext(true));
The most important is the second param of load() method, it's a LoaderContext. Reference:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html#load()
Although I set the crossdomain file in the server, without the "new LoaderContext(true)", it won't read the crossdomain file. That's why it doesn't work at first.
If you have the same problem, hope it's helpful to you!
I am displaying an image in figure window in MATLAB using following code.
im = imread('Image02.tif');
processAndDisplayImage(im);
hImage = image(im);
set(hImage,'ButtonDownFcn',#clickInImage);
But problem is that the third line above makes the image changed for some reason I don't know. Is there any way to get image handle without the modification?
UPDATE: Resolved the problem. Please refer to my answer below.
The image graphical command cannot change the image. I can only guess that it shows the image in a way you don't want it. Inspect the range of the image -
max(im(:));
and also the type:
class(im);
and try to figure out what is wrong
Perhaps you could modify processAndDisplayImage so that it returns a handle to the displayed image as an output variable?
Instead of
hImage = image(im);
I used following to solve my problem.
[hImage hfig ha] = imhandles(gcf);
But I still don't understand image command does to the actual image displayed on figure.
I have uploaded a photo in WordPress. I am trying to post a thumbnail of the image using a predetermined width while constraining the height proportionally.
In functions.js:
add_image_size('width-130', 130, 0, false);
On the page that outputs the thumbnail:
the_post_thumbnail('width-130');
According to the WordPress docs(http://codex.wordpress.org/Function_Reference/add_image_size), it says:
WordPress will create a copy of the post thumbnail with the specified
dimensions when you upload a new thumbnail.
Currently it is outputting the full thumbnail image with a width attribute of 130. This still requires the full size image to load, which is not what I want. I would like for WordPress to create an actual copy of the post thumbnail with the correct dimensions, and not just to set the width attribute. How can I achieve this?
I discovered my mistake.
Since I had not re-uploaded the image file, it was still trying to access the full size image which was the assigned image for that post, while adding the width attribute. Once I re-uploaded the image, the add_image_size() function is now actually creating a copy of the thumbnail with the correct dimensions.
I apologize for asking this question. If the community wants, I can close it but I figure it might be good reference for WordPress newbies such as myself.
Use this plugin to regenerate thumbnails.
http://wordpress.org/plugins/regenerate-thumbnails/
In case anyone runs across a similar problem, this may help. add_image_size generates derivatives that are smaller, but not bigger or the same size. Thus if you are trying to make a monochrome derivative image, uploading an image the same size as the monochrome, it will not be available and techniques like this one won't work.
I got strange behaviour when I added filter for attachment_fields_to_save, when I save the images, it does not want to save image metadata such as title, description and caption.
Why I need to add this filter? Because I have lots of custom sizes using this code:
add_image_size("imagesize-940x360", 940, 360, true);
And the image may not correctly put in good place, so the user need to use Wordpress awesome tools to edit the image like cropping and scaling.
For some silly reason (or perhaps this is bug), the Wordpress does not generate image for custom image sizes.
In order to achieve generation for custom sizes, I need to add filter when user press save button in the Wordpress image editor. Here is the piece code that I been using:
add_filter("attachment_fields_to_save", "rl_regenerate_image", 99, 2);
function rl_regenerate_image($post, $attachment)
{
$id = $post['ID'];
$fullsizepath = get_attached_file($id);
wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $fullsizepath));
return true;
}
The code above generates the custom sizes when user edit the image correctly but sadly it does not save all updated metadata images such as title, caption and description.
Do you guys know how to solve this problem? So what I would like to achieve is how to generate "edited" images for custom sizes and save the metadata correctly.
Thanks in advance!
In case this hasn't been solved yet, or for any Googler's out there.. Here's a plugin called Post Thumbnail Editor that lets you edit individual custom image sizes. Works well.
http://wordpress.org/extend/plugins/post-thumbnail-editor/