I have a custom asp.net server control to display images.What I need now is to draw a rectangle on the center of image and the rectangle should be re sizable by dragging on its edges.Is it possible to accomplish this using JavaScript ?. I need to embed that script in that control. Is it possible ?
You can include a javascript file in a server control.
Add a reference to the assemblyinfo.cs
[assembly: WebResource("Custom.js", "text/javascript")]
Then a reference on the PreRender:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string resourceName = "Custom.js";
ClientScriptManager cs = this.Page.ClientScript;
cs.RegisterClientScriptResource(typeof(CustomControls.Custom), resourceName);
}
Here is a nice article on the subject
Related
I am currently using Umbraco Version: 8.5.3 and I have used media picker to select the pdf file and it displays the link on the site.
What I want now is to get the first page of the pdf and display it as an image on my site.
Any help would much appreciated.
Thanks.
It's not an easy task, but the best approach would be to generate the image when the PDF is uploaded.
You could create a new property in the File Media Type to save the thumbnail. Use an Upload field for this:
Note: if you put the Thumbnail property the first one it will display in the media section :)
To create the preview you will need to hook up a listener to the Saving event of the MediaService. you need to use a Component for this.
In the following example, I'm using the Ghoscript.NET wrapper to create an image from the PDF. You will need to use the Ghostscript library also. To get the library you will need to install the program and grab the dlls from the folder where it's installed. It looks like the versions over 9.26 give some errors. This example has been tested with version 9.26.
using Ghostscript.NET;
using System;
using System.Drawing.Imaging;
using System.IO;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
namespace PdfPreview
{
public class PdfPreviewComponent : IComponent
{
private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider;
// we need to inject the IContentTypeBaseServiceProvider. It's used by the helper that set the image value.
public PdfPreviewComponent(IContentTypeBaseServiceProvider contentTypeBaseServiceProvider)
{
_contentTypeBaseServiceProvider = contentTypeBaseServiceProvider;
}
public void Initialize()
{
// attach the handler to the event
MediaService.Saving += MediaService_Saving;
}
private void MediaService_Saving(Umbraco.Core.Services.IMediaService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IMedia> e)
{
foreach (IMedia item in e.SavedEntities)
{
if (item.ContentType.Alias.Equals(Umbraco.Web.PublishedModels.File.ModelTypeAlias))
{
var filePropertyValue = (string)item.GetValue("umbracoFile");
if (filePropertyValue != null && !string.IsNullOrEmpty(filePropertyValue))
{
var isPdf = filePropertyValue.EndsWith(".pdf", StringComparison.InvariantCultureIgnoreCase);
if (isPdf)
{
// Ghostscript.NET needs to know where the Ghostscripts dlls are
var binpath = AppDomain.CurrentDomain.RelativeSearchPath;
string gsDllPath = Path.Combine(binpath, Environment.Is64BitProcess ? #"gsdll64.dll" : #"gsdll32.dll");
var version = new GhostscriptVersionInfo(new Version(0, 0, 0), gsDllPath, string.Empty, GhostscriptLicense.GPL);
using (var rasterizer = new Ghostscript.NET.Rasterizer.GhostscriptRasterizer())
{
// we get the actual location in the server of our PDF being upload
var location = System.Web.Hosting.HostingEnvironment.MapPath(filePropertyValue);
// and we open it with the rasterizer.
rasterizer.Open(location, version, true);
// we get the first page as an Image.
var firstPageAsImage = rasterizer.GetPage(200, 200, 1);
using (var stream = new MemoryStream())
{
// we need to transform the Image to Stream...
firstPageAsImage.Save(stream, ImageFormat.Png);
//...because this helper only accepts a Stream
item.SetValue(_contentTypeBaseServiceProvider, "thumbnail", "thumbnail.png", stream);
}
}
}
}
}
}
}
public void Terminate()
{
}
}
// we use a Composer to add our Component to the list of Components. Here we use the ComponentComposer helper base class to do it.
public class PdfPreviewComposer : ComponentComposer<PdfPreviewComponent> { }
}
NOTE: we don't need to save the Umbraco node in the event handler because all this is happening right before saving. After this, the saving of the file will actually occur in Umbraco.
I try to convert sample .net application with P/Invoke to javascript with JSIL.
C# code:
[DllImport("JSTestLib", EntryPoint = "Get42", CallingConvention = CallingConvention.Cdecl)]
public unsafe static extern int Get42();
Generated javascript:
$.ExternalMethod({Static:true , Public:true }, "Get42",
JSIL.MethodSignature.Return($.Int32)
);
Where should I add implementation of the Get42 method in javascript? Should I register this method manually in JSIL?
I have only an error now:
The external method 'System.Int32 Get42()' of type 'Test.Program' has
not been implemented.
Just use JSIL.ImplementExternals - take a look at JSIL.Core.js for examples
I have a wicket application in which I have added the javascript files within the markup html:
<script src="script/jquery.min.js" type="text/javascript"></script>
My javascript files are not placed beside my .java or .html files, they are in different location in the server as can be seen on previous script declaration.
My question is: Is it possible to add these javascript files depending on the application mode? I.E. if the application is in development mode, load one javascript file, if it is in production load this other one.
Thanks!
PS: the idea is to load "min" version on production but the extended files on development so debugging becomes posible
NOTE: Watching different answers here I re-state: the problem is not finding when the wicket app is in development or deployment mode, I know that, but is about how to change html markup or adding different JavaScript resources
extendig the answer of #rotsch you can do it in wicket 1.5 with :
#Override
public void renderHead(IHeaderResponse response) {
if(DEVELOPMENT)
response.renderString("<script type=\"text/javascript\" src=\"url1\"></script>");
else
response.renderString("<script type=\"text/javascript\" src=\"url2\"></script>");
}
https://cwiki.apache.org/WICKET/migration-to-wicket-15.html#MigrationtoWicket1.5-RemovedHeaderContributorandfriends.
You can find out in which mode you are with the following code:
RuntimeConfigurationType.DEPLOYMENT.equals(getApplication().getConfigurationType())
or
RuntimeConfigurationType.DEVELOPMENT.equals(getApplication().getConfigurationType())
I use this directory layout:
resources
|---JQueryResource.java
|---jquery-1.6.4.js
|---jquery-1.6.4.min.js
With this class:
public class JQueryResource {
/**
* Must be called in a RequestCycle.
*
* #return Url for the jQuery library.
*/
public static String getURL() {
if (Application.get().usesDevelopmentConfig()) {
Url url =
RequestCycle.get().mapUrlFor(
new PackageResourceReference(JQueryResource.class, "jquery-1.6.4.js"),
null);
return url.toString();
} else {
Url url =
RequestCycle.get().mapUrlFor(
new PackageResourceReference(JQueryResource.class,
"jquery-1.6.4.min.js"), null);
return url.toString();
}
}
}
This is how I add the resource to my page.
#Override
public void renderHead(IHeaderResponse a_response) {
a_response.renderJavaScriptReference(JQueryResource.getURL());
}
You could use pack:tag to compress all your resources: http://sourceforge.net/projects/packtag/
In your web.xml/.properties file you can specify whether to pack it or not depending on your production mode.
I set a property in a properties file with I add to the path when starting the VM.
Then I do a if else similar to the PHP answer.
I've tried really hard to include a JavaScript file with my WebPart as a resource. The web part class and the flexidgrid.js file are both in the root level of the project. The Web Part is created in DisplaySearchResults.js:
namespace DisplaySearchResults
{
public class DisplaySearchResults : WebPart
{
### Hidden Irrelevant Stuff Here ###
protected override void CreateChildControls()
{
### Hidden Irrelevant Stuff Here ###
### Load JavaScript Code Here ###
string scriptURL = Page.ClientScript.GetWebResourceUrl(typeof(DisplaySearchResults), "DisplaySearchResults.flexigrid.js");
ClientScriptManager cs = Page.ClientScript;
if (!cs.IsClientScriptBlockRegistered(ByeByeIncludeScriptKey))
cs.RegisterClientScriptInclude(this.GetType(), ByeByeIncludeScriptKey, scriptURL);
}
### Hidden Irrelevant Stuff Here ###
}
}
The AssemblyInfo.cs for DisplaySearchResults looks like this:
[assembly: WebResource("DisplaySearchResults.flexigrid.js", "text/javascript")]
But for some reason the WebResource.axd file still comes up as 404.
Make sure that file's Build Action is set to "Embedded Resource" in the properties for that file.
I had already set the Embedded Resource - it turned out I needed the fully qualified Assembly name - Company.UI.Web.DisplaySearchResults - which I got from right clicking on the properties menu of the project. On the application tab, there is the proper Assembly name.
So, instead of:
[assembly: WebResource("DisplaySearchResults.flexigrid.js", "text/javascript")]
I should have put:
[assembly: WebResource("Company.UI.Web.DisplaySearchResults.flexigrid.js", "text/javascript")]
How to tag images in the image itself in a web page?
I know Taggify, but... is there other options?
Orkut also does it to tag people faces... How is it done?
Anyone knows any public framework that is able to do it?
See a sample bellow from Taggify:
I know this isn't javascript but C# 3.0 has an API for doing this. The System.Windows.Media.Imaging namespace has a class called BitmapMetadata which can be used to read and write image metadata (which is stored in the image itself). Here is a method for retrieving the metadata for an image given a file path:
public static BitmapMetadata GetMetaData(string path)
{
using (Stream s = new System.IO.FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
{
var decoder = BitmapDecoder.Create(s, BitmapCreateOptions.None, BitmapCacheOption.OnDemand);
var frame = decoder.Frames.FirstOrDefault();
if (frame != null)
{
return frame.Metadata as BitmapMetadata;
}
return null;
}
}
The BitmapMetadata class has a property for tags as well as other common image metadata. To save metadata back to the image, you can use the InPlaceBitmapMetadataWriter Class.
There's a map tag in HTML that could be used in conjunction with Javascript to 'tag' different parts of an image.
You can see the details here.
I will re-activate this question and help a bit. Currently the only thing i have found about is http://www.sanisoft.com/downloads/imgnotes-0.2/example.html . A jQuery tagging implementation. If anyone knows about another way please tell us.
;)
You can check out Image.InfoCards (IIC) at http://www.imageinfocards.com . With the IIC meta-data utilities you can add meta-data in very user-friendly groups called "cards".
The supplied utilities (including a Java applet) allow you to tag GIF's, JPEG's and PNG's without changing them visually.
IIC is presently proprietary but there are plans to make it an open protocol in Q1 2009.
The difference between IIC and others like IPTC/DIG35/DublinCore/etc is that it is much more consumer-centric and doesn't require a CS degree to understand and use it...